feat(Partials): add DMChannel/MessageReaction#fetch() and Parti… (#3261)

* add DMChannel#fetch() & Action#getChannel({recipients})

* ref for MessageReaction partial

* typings

* add PartialTypes.REACTION

* accommodate for fully removed reactions

* fix incorrect wording and typo

* typings: MessageReaction#count is nullable

* typings: mark MessageReaction#partial as readonly

Co-Authored-By: Vlad Frangu <kingdgrizzle@gmail.com>

* fix(User): fetch dm channel if cached one is partial

* docs: add missing comma

Co-Authored-By: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
izexi
2019-09-10 15:09:06 +01:00
committed by Crawl
parent 6f83e71555
commit b0047c424b
9 changed files with 80 additions and 20 deletions

View File

@@ -50,6 +50,28 @@ class ReactionStore extends DataStore {
return this.client.api.channels(this.message.channel.id).messages(this.message.id).reactions.delete()
.then(() => this.message);
}
_partial(emoji) {
const id = emoji.id || emoji.name;
const existing = this.get(id);
return !existing || existing.partial;
}
async _fetchReaction(reactionEmoji, cache) {
const id = reactionEmoji.id || reactionEmoji.name;
const existing = this.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 (!data.reactions || !data.reactions.some(r => (r.emoji.id || r.emoji.name) === id)) {
reactionEmoji.reaction._patch({ count: 0 });
this.message.reactions.remove(id);
return existing;
}
for (const reaction of data.reactions) {
if (this._partial(reaction.emoji)) this.add(reaction, cache);
}
return existing;
}
}
module.exports = ReactionStore;