fix(MessageReaction): fetching a removed partial custom emoji (#3955)

* fix: handling GuildEmoji within fetch()

* refactor: remove unused "private" methods

* refactor: make use of Message#fetch() to patch
This commit is contained in:
izexi
2020-03-17 17:52:43 +00:00
committed by GitHub
parent 2be9ebaad2
commit a36a65b36a
2 changed files with 6 additions and 28 deletions

View File

@@ -64,32 +64,6 @@ class ReactionManager extends BaseManager {
.reactions.delete()
.then(() => this.message);
}
_partial(emoji) {
const id = emoji.id || emoji.name;
const existing = this.cache.get(id);
return !existing || existing.partial;
}
async _fetchReaction(reactionEmoji, cache) {
const id = reactionEmoji.id || reactionEmoji.name;
const existing = this.cache.get(id);
if (!this._partial(reactionEmoji)) return existing;
const data = await this.client.api
.channels(this.message.channel.id)
.messages(this.message.id)
.get();
if (this.message.partial) this.message._patch(data);
if (!data.reactions || !data.reactions.some(r => (r.emoji.id || r.emoji.name) === id)) {
reactionEmoji.reaction._patch({ count: 0 });
this.message.reactions.cache.delete(id);
return existing;
}
for (const reaction of data.reactions) {
if (this._partial(reaction.emoji)) this.add(reaction, cache);
}
return existing;
}
}
module.exports = ReactionManager;

View File

@@ -101,8 +101,12 @@ class MessageReaction {
* Fetch this reaction.
* @returns {Promise<MessageReaction>}
*/
fetch() {
return this.message.reactions._fetchReaction(this.emoji, true);
async fetch() {
const message = await this.message.fetch();
const existing = message.reactions.cache.get(this.emoji.id || this.emoji.name);
// The reaction won't get set when it has been completely removed
this._patch(existing || { count: 0 });
return this;
}
toJSON() {