From 2341d13615fb0a4649ba719c072661b65a4927a5 Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Tue, 19 Mar 2019 19:32:11 +0000 Subject: [PATCH] fix: messageReactionRemove not emitting for partial messages (#3125) --- src/client/actions/Action.js | 13 +++++++++++++ src/client/actions/MessageReactionAdd.js | 9 +++++++++ src/client/actions/MessageReactionRemove.js | 3 +-- .../websocket/handlers/MESSAGE_REACTION_ADD.js | 11 +---------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/client/actions/Action.js b/src/client/actions/Action.js index 09faae9e2..0c798089b 100644 --- a/src/client/actions/Action.js +++ b/src/client/actions/Action.js @@ -43,6 +43,19 @@ class GenericAction { }) : channel.messages.get(id)); } + + 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; + } } module.exports = GenericAction; diff --git a/src/client/actions/MessageReactionAdd.js b/src/client/actions/MessageReactionAdd.js index b7400cf77..185b980ad 100644 --- a/src/client/actions/MessageReactionAdd.js +++ b/src/client/actions/MessageReactionAdd.js @@ -1,6 +1,7 @@ 'use strict'; const Action = require('./Action'); +const { Events } = require('../../util/Constants'); /* { user_id: 'id', @@ -31,6 +32,14 @@ class MessageReactionAdd extends Action { me: user.id === this.client.user.id, }); reaction._add(user); + /** + * Emitted whenever a reaction is added to a cached message. + * @event Client#messageReactionAdd + * @param {MessageReaction} messageReaction The reaction object + * @param {User} user The user that applied the guild or reaction emoji + */ + this.client.emit(Events.MESSAGE_REACTION_ADD, reaction, user); + return { message, reaction, user }; } } diff --git a/src/client/actions/MessageReactionRemove.js b/src/client/actions/MessageReactionRemove.js index e5d4f8413..4e7995f8e 100644 --- a/src/client/actions/MessageReactionRemove.js +++ b/src/client/actions/MessageReactionRemove.js @@ -26,8 +26,7 @@ class MessageReactionRemove extends Action { if (!message) return false; // Verify reaction - const emojiID = data.emoji.id || decodeURIComponent(data.emoji.name); - const reaction = message.reactions.get(emojiID); + const reaction = this.getReaction(data, message, user); if (!reaction) return false; reaction._remove(user); /** diff --git a/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js b/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js index 6d0bbb059..e219b4a52 100644 --- a/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +++ b/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js @@ -1,14 +1,5 @@ 'use strict'; -const { Events } = require('../../../util/Constants'); - module.exports = (client, packet) => { - const { user, reaction } = client.actions.MessageReactionAdd.handle(packet.d); - /** - * Emitted whenever a reaction is added to a cached message. - * @event Client#messageReactionAdd - * @param {MessageReaction} messageReaction The reaction object - * @param {User} user The user that applied the guild or reaction emoji - */ - if (reaction) client.emit(Events.MESSAGE_REACTION_ADD, reaction, user); + client.actions.MessageReactionAdd.handle(packet.d); };