Skip to content
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

Implement caching of members from message data #3684

Merged
merged 11 commits into from
Jan 19, 2020
18 changes: 11 additions & 7 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
monbrey marked this conversation as resolved.
Show resolved Hide resolved
*/
this.member = this.guild ? this.guild.member(this.author) || null : null;

/**
* Whether or not this message is pinned
* @type {boolean}
Expand Down Expand Up @@ -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;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/structures/MessageMentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down