revert: "feat(Partials): add DMChannel/MessageReaction#fetch()… (#3468)

This reverts commit b0047c424b.
This commit is contained in:
Crawl
2019-09-10 19:49:56 +02:00
committed by GitHub
parent dad0cd8e81
commit 321beb73bd
9 changed files with 20 additions and 80 deletions

View File

@@ -36,7 +36,6 @@ class GenericAction {
return data.channel || this.getPayload({
id,
guild_id: data.guild_id,
recipients: [data.author || { id: data.user_id }],
}, this.client.channels, id, PartialTypes.CHANNEL);
}
@@ -53,9 +52,9 @@ class GenericAction {
const id = data.emoji.id || decodeURIComponent(data.emoji.name);
return this.getPayload({
emoji: data.emoji,
count: message.partial ? null : 0,
count: 0,
me: user.id === this.client.user.id,
}, message.reactions, id, PartialTypes.REACTION);
}, message.reactions, id, PartialTypes.MESSAGE);
}
getMember(data, guild) {

View File

@@ -26,8 +26,11 @@ class MessageReactionAdd extends Action {
if (!message) return false;
// Verify reaction
const reaction = this.getReaction(data, message, user);
if (!reaction) return false;
const reaction = message.reactions.add({
emoji: data.emoji,
count: 0,
me: user.id === this.client.user.id,
});
reaction._add(user);
/**
* Emitted whenever a reaction is added to a cached message.

View File

@@ -50,28 +50,6 @@ 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;

View File

@@ -56,15 +56,7 @@ class DMChannel extends Channel {
* @readonly
*/
get partial() {
return this.lastMessageID === undefined;
}
/**
* Fetch this DMChannel.
* @returns {Promise<DMChannel>}
*/
fetch() {
return this.recipient.createDM();
return !this.recipient;
}
/**

View File

@@ -27,6 +27,12 @@ class MessageReaction {
*/
this.me = data.me;
/**
* The number of people that have given the same reaction
* @type {number}
*/
this.count = data.count || 0;
/**
* The users that have given this reaction, mapped by their ID
* @type {ReactionUserStore<Snowflake, User>}
@@ -34,16 +40,6 @@ class MessageReaction {
this.users = new ReactionUserStore(client, undefined, this);
this._emoji = new ReactionEmoji(this, data.emoji);
this._patch(data);
}
_patch(data) {
/**
* The number of people that have given the same reaction
* @type {?number}
*/
this.count = typeof data.count === 'number' ? data.count : null;
}
/**
@@ -67,36 +63,18 @@ class MessageReaction {
return this._emoji;
}
/**
* Whether or not this reaction is a partial
* @type {boolean}
* @readonly
*/
get partial() {
return this.count === null;
}
/**
* Fetch this reaction.
* @returns {Promise<MessageReaction>}
*/
fetch() {
return this.message.reactions._fetchReaction(this.emoji, true);
}
toJSON() {
return Util.flatten(this, { emoji: 'emojiID', message: 'messageID' });
}
_add(user) {
if (this.partial) return;
this.users.set(user.id, user);
if (!this.me || user.id !== this.message.client.user.id || this.count === 0) this.count++;
if (!this.me) this.me = user.id === this.message.client.user.id;
}
_remove(user) {
if (this.partial) return;
this.users.delete(user.id);
if (!this.me || user.id !== this.message.client.user.id) this.count--;
if (user.id === this.message.client.user.id) this.me = false;

View File

@@ -211,7 +211,7 @@ class User extends Base {
*/
async createDM() {
const { dmChannel } = this;
if (dmChannel && !dmChannel.partial) return dmChannel;
if (dmChannel) return dmChannel;
const data = await this.client.api.users(this.client.user.id).channels.post({ data: {
recipient_id: this.id,
} });

View File

@@ -287,7 +287,6 @@ exports.ShardEvents = {
* * CHANNEL (only affects DMChannels)
* * GUILD_MEMBER
* * MESSAGE
* * REACTION
* <warn>Partials require you to put checks in place when handling data, read the Partials topic listed in the
* sidebar for more information.</warn>
* @typedef {string} PartialType
@@ -297,7 +296,6 @@ exports.PartialTypes = keyMirror([
'CHANNEL',
'GUILD_MEMBER',
'MESSAGE',
'REACTION',
]);
/**