feat(Message/Mentions): implement caching of members (#3684)

* Convert message#member to a getter

*  Try to cache members from data in message payloads

* Cache mentioned members

* Revert Message#member getter - breaking change

* Revise member caching

* Revise member mention caching

* Pass member to _addMember correctly

* Use message.guild instead of this.guild

Co-Authored-By: SpaceEEC <spaceeec@yahoo.com>

* Merge if's onto one line

* fix(Message): use this.author.id to check cache

Discord does not send an id in the member data here

* chore(Message): reindent equals

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Ryan Munro
2020-01-19 22:27:57 +11:00
committed by SpaceEEC
parent 6ab46491c8
commit 0f49d67e2e
2 changed files with 14 additions and 7 deletions

View File

@@ -63,13 +63,6 @@ class Message {
*/
this.author = this.client.dataManager.newUser(data.author, !data.webhook_id);
/**
* Represents the author of the message as a guild member
* Only available if the message comes from a guild where the author is still a member
* @type {?GuildMember}
*/
this.member = this.guild ? this.guild.member(this.author) || null : null;
/**
* Whether or not this message is pinned
* @type {boolean}
@@ -155,6 +148,17 @@ class Message {
* @private
*/
this._edits = [];
if (data.member && this.guild && this.author && !this.guild.members.has(this.author.id)) {
this.guild._addMember(Object.assign(data.member, { user: this.author }), false);
}
/**
* Represents the author of the message as a guild member
* Only available if the message comes from a guild where the author is still a member
* @type {?GuildMember}
*/
this.member = this.guild ? this.guild.member(this.author) || null : null;
}
/**

View File

@@ -24,6 +24,9 @@ class MessageMentions {
let user = message.client.users.get(mention.id);
if (!user) user = message.client.dataManager.newUser(mention);
this.users.set(user.id, user);
if (mention.member && message.guild && !message.guild.members.has(mention.id)) {
message.guild._addMember(Object.assign(mention.member, { user }), false);
}
}
}
} else {