New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Teams): backport support for teams #3357
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
83f9fff
feat(Teams): backport support for teams
SpaceEEC e1b4e34
fix(TeamMember): fix name of client property
SpaceEEC 66fbe3b
refactor(OAuth2Application): make team nullable instead of optional
SpaceEEC edadb0e
typings(OAuth2Application): make team nullable instable of optional
SpaceEEC ee9b06d
docs(OAuth2Application): deprecate and add an info to team property
SpaceEEC File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
const Snowflake = require('../util/Snowflake'); | ||
const Collection = require('../util/Collection'); | ||
const TeamMember = require('./TeamMember'); | ||
const Constants = require('../util/Constants'); | ||
|
||
/** | ||
* Represents a Client OAuth2 Application Team. | ||
*/ | ||
class Team { | ||
constructor(client, data) { | ||
/** | ||
* The client that instantiated the team | ||
* @name Team#client | ||
* @type {Client} | ||
* @readonly | ||
*/ | ||
Object.defineProperty(this, 'client', { value: client }); | ||
|
||
this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* The ID of the Team | ||
* @type {Snowflake} | ||
*/ | ||
this.id = data.id; | ||
|
||
/** | ||
* The name of the Team | ||
* @type {string} | ||
*/ | ||
this.name = data.name; | ||
|
||
/** | ||
* The Team's icon hash | ||
* @type {?string} | ||
*/ | ||
this.icon = data.icon || null; | ||
|
||
/** | ||
* The Team's owner id | ||
* @type {?string} | ||
*/ | ||
this.ownerID = data.owner_user_id || null; | ||
|
||
/** | ||
* The Team's members | ||
* @type {Collection<Snowflake, TeamMember>} | ||
*/ | ||
this.members = new Collection(); | ||
|
||
for (const memberData of data.members) { | ||
const member = new TeamMember(this.client, this, memberData); | ||
this.members.set(member.id, member); | ||
} | ||
} | ||
|
||
/** | ||
* The owner of the team | ||
* @type {?TeamMember} | ||
* @readonly | ||
*/ | ||
get owner() { | ||
return this.members.get(this.ownerID) || null; | ||
} | ||
|
||
/** | ||
* The timestamp the team was created at | ||
* @type {number} | ||
* @readonly | ||
*/ | ||
get createdTimestamp() { | ||
return Snowflake.deconstruct(this.id).timestamp; | ||
} | ||
|
||
/** | ||
* The time the team was created at | ||
* @type {Date} | ||
* @readonly | ||
*/ | ||
get createdAt() { | ||
return new Date(this.createdTimestamp); | ||
} | ||
|
||
/** | ||
* A link to the teams's icon. | ||
* @type {?string} | ||
* @readonly | ||
*/ | ||
get iconURL() { | ||
if (!this.icon) return null; | ||
return Constants.Endpoints.CDN(this.client.options.http.cdn).TeamIcon(this.id, this.icon); | ||
} | ||
|
||
/** | ||
* When concatenated with a string, this automatically returns the Team's name instead of the | ||
* Team object. | ||
* @returns {string} | ||
* @example | ||
* // Logs: Team name: My Team | ||
* console.log(`Team name: ${team}`); | ||
*/ | ||
toString() { | ||
return this.name; | ||
} | ||
} | ||
|
||
module.exports = Team; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const { MembershipStates } = require('../util/Constants'); | ||
|
||
/** | ||
* Represents a Client OAuth2 Application Team Member. | ||
*/ | ||
class TeamMember { | ||
constructor(client, team, data) { | ||
/** | ||
* The client that instantiated the Team Member | ||
* @name TeamMember#client | ||
* @type {Client} | ||
* @readonly | ||
*/ | ||
Object.defineProperty(this, 'client', { value: client }); | ||
|
||
/** | ||
* The Team this member is part of | ||
* @type {Team} | ||
*/ | ||
this.team = team; | ||
|
||
this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* The permissions this Team Member has with regard to the team | ||
* @type {string[]} | ||
*/ | ||
this.permissions = data.permissions; | ||
|
||
/** | ||
* The membership state this Team Member has with regard to the team | ||
* @type {MembershipStates} | ||
*/ | ||
this.membershipState = MembershipStates[data.membership_state]; | ||
|
||
/** | ||
* The user for this Team Member | ||
* @type {User} | ||
*/ | ||
this.user = this.client.dataManager.newUser(data.user); | ||
} | ||
|
||
/** | ||
* The ID of the Team Member | ||
* @type {Snowflake} | ||
* @readonly | ||
*/ | ||
get id() { | ||
return this.user.id; | ||
} | ||
|
||
/** | ||
* When concatenated with a string, this automatically returns the team members's mention instead of the | ||
* TeamMember object. | ||
* @returns {string} | ||
* @example | ||
* // Logs: Team Member's mention: <@123456789> | ||
* console.log(`Team Member's mention: ${teamMember}`); | ||
*/ | ||
toString() { | ||
return this.user.toString(); | ||
} | ||
} | ||
|
||
module.exports = TeamMember; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The team property should always exist as null or Team, not excluding the property if no data.team, so the object keeps consistent shape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, and also, it should be deprecated since it will be gone in v12.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would such a deprecation look like? Emitting a process warning on access seems unjustified as there is no way to fix this before v12. Maybe a warn or info in the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At minimum just a docstring @deprecated. But probably that with an explanation (in a warn or info tag) in the description.