fix(Partials): Client#event:messageUpdate(oldMessage) and MessageReactionAdd on guild channels (#3250)

* ref: add getPayload and use for other get* methods

* return existing data.*

* use Action.getUser()
This commit is contained in:
izexi
2019-05-07 20:56:39 +01:00
committed by Amish Shah
parent 3d4513268d
commit 0dd3ed72ef
3 changed files with 39 additions and 34 deletions

View File

@@ -23,47 +23,52 @@ class GenericAction {
return data; return data;
} }
getChannel(data) { getPayload(data, store, id, partialType, cache) {
const id = data.channel_id || data.id; const existing = store.get(id);
return data.channel || (this.client.options.partials.includes(PartialTypes.CHANNEL) ? if (!existing && this.client.options.partials.includes(partialType)) {
this.client.channels.add({ return store.add(data, cache);
id, }
guild_id: data.guild_id, return existing;
}) :
this.client.channels.get(id));
} }
getMessage(data, channel, cache = true) { getChannel(data) {
const id = data.channel_id || data.id;
return data.channel || this.getPayload({
id,
guild_id: data.guild_id,
}, this.client.channels, id, PartialTypes.CHANNEL);
}
getMessage(data, channel, cache) {
const id = data.message_id || data.id; const id = data.message_id || data.id;
return data.message || (this.client.options.partials.includes(PartialTypes.MESSAGE) ? return data.message || this.getPayload({
channel.messages.add({ id,
id, channel_id: channel.id,
channel_id: channel.id, guild_id: data.guild_id || (channel.guild ? channel.guild.id : null),
guild_id: data.guild_id || (channel.guild ? channel.guild.id : null), }, channel.messages, id, PartialTypes.MESSAGE, cache);
}, cache) :
channel.messages.get(id));
} }
getReaction(data, message, user) { getReaction(data, message, user) {
const emojiID = data.emoji.id || decodeURIComponent(data.emoji.name); const id = data.emoji.id || decodeURIComponent(data.emoji.name);
const existing = message.reactions.get(emojiID); return this.getPayload({
if (!existing && this.client.options.partials.includes(PartialTypes.MESSAGE)) { emoji: data.emoji,
return message.reactions.add({ count: 0,
emoji: data.emoji, me: user.id === this.client.user.id,
count: 0, }, message.reactions, id, PartialTypes.MESSAGE);
me: user.id === this.client.user.id,
});
}
return existing;
} }
getMember(data, guild) { getMember(data, guild) {
const userID = data.user.id; const id = data.user.id;
const existing = guild.members.get(userID); return this.getPayload({
if (!existing && this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)) { user: {
return guild.members.add({ user: { id: userID } }); id,
} },
return existing; }, guild.members, id, PartialTypes.GUILD_MEMBER);
}
getUser(data) {
const id = data.user_id;
return data.user || this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
} }
} }

View File

@@ -14,7 +14,7 @@ class MessageReactionAdd extends Action {
handle(data) { handle(data) {
if (!data.emoji) return false; if (!data.emoji) return false;
const user = data.user || this.client.users.get(data.user_id); const user = this.getUser(data);
if (!user) return false; if (!user) return false;
// Verify channel // Verify channel

View File

@@ -14,7 +14,7 @@ class MessageReactionRemove extends Action {
handle(data) { handle(data) {
if (!data.emoji) return false; if (!data.emoji) return false;
const user = this.client.users.get(data.user_id); const user = this.getUser(data);
if (!user) return false; if (!user) return false;
// Verify channel // Verify channel