mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
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:
@@ -56,7 +56,15 @@ class DMChannel extends Channel {
|
||||
* @readonly
|
||||
*/
|
||||
get partial() {
|
||||
return !this.recipient;
|
||||
return this.lastMessageID === undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch this DMChannel.
|
||||
* @returns {Promise<DMChannel>}
|
||||
*/
|
||||
fetch() {
|
||||
return this.recipient.createDM();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,12 +27,6 @@ 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>}
|
||||
@@ -40,6 +34,16 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,18 +67,36 @@ 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;
|
||||
|
||||
@@ -211,7 +211,7 @@ class User extends Base {
|
||||
*/
|
||||
async createDM() {
|
||||
const { dmChannel } = this;
|
||||
if (dmChannel) return dmChannel;
|
||||
if (dmChannel && !dmChannel.partial) return dmChannel;
|
||||
const data = await this.client.api.users(this.client.user.id).channels.post({ data: {
|
||||
recipient_id: this.id,
|
||||
} });
|
||||
|
||||
Reference in New Issue
Block a user