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;
}
getChannel(data) {
const id = data.channel_id || data.id;
return data.channel || (this.client.options.partials.includes(PartialTypes.CHANNEL) ?
this.client.channels.add({
id,
guild_id: data.guild_id,
}) :
this.client.channels.get(id));
getPayload(data, store, id, partialType, cache) {
const existing = store.get(id);
if (!existing && this.client.options.partials.includes(partialType)) {
return store.add(data, cache);
}
return existing;
}
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;
return data.message || (this.client.options.partials.includes(PartialTypes.MESSAGE) ?
channel.messages.add({
id,
channel_id: channel.id,
guild_id: data.guild_id || (channel.guild ? channel.guild.id : null),
}, cache) :
channel.messages.get(id));
return data.message || this.getPayload({
id,
channel_id: channel.id,
guild_id: data.guild_id || (channel.guild ? channel.guild.id : null),
}, channel.messages, id, PartialTypes.MESSAGE, cache);
}
getReaction(data, message, user) {
const emojiID = data.emoji.id || decodeURIComponent(data.emoji.name);
const existing = message.reactions.get(emojiID);
if (!existing && this.client.options.partials.includes(PartialTypes.MESSAGE)) {
return message.reactions.add({
emoji: data.emoji,
count: 0,
me: user.id === this.client.user.id,
});
}
return existing;
const id = data.emoji.id || decodeURIComponent(data.emoji.name);
return this.getPayload({
emoji: data.emoji,
count: 0,
me: user.id === this.client.user.id,
}, message.reactions, id, PartialTypes.MESSAGE);
}
getMember(data, guild) {
const userID = data.user.id;
const existing = guild.members.get(userID);
if (!existing && this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)) {
return guild.members.add({ user: { id: userID } });
}
return existing;
const id = data.user.id;
return this.getPayload({
user: {
id,
},
}, 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) {
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;
// Verify channel

View File

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