fix(ThreadChannel): check for existence of properties when patching (#5961)

Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
monbrey
2021-07-01 18:58:20 +10:00
committed by GitHub
parent 71fb33a5fe
commit 9ac68670d7

View File

@@ -50,12 +50,15 @@ class ThreadChannel extends Channel {
*/ */
this.name = data.name; this.name = data.name;
if ('parent_id' in data) {
/** /**
* The ID of the parent channel to this thread * The ID of the parent channel to this thread
* @type {Snowflake} * @type {Snowflake}
*/ */
this.parentID = data.parent_id; this.parentID = data.parent_id;
}
if ('thread_metadata' in data) {
/** /**
* Whether the thread is locked * Whether the thread is locked
* @type {boolean} * @type {boolean}
@@ -68,43 +71,53 @@ class ThreadChannel extends Channel {
*/ */
this.archived = data.thread_metadata.archived; this.archived = data.thread_metadata.archived;
/**
* The id of the member that created this thread
* @type {?Snowflake}
*/
this.ownerID = data.owner_id;
/** /**
* How long in minutes after recent activity before the thread is automatically archived * How long in minutes after recent activity before the thread is automatically archived
* @type {number} * @type {number}
*/ */
this.autoArchiveDuration = data.thread_metadata.auto_archive_duration; this.autoArchiveDuration = data.thread_metadata.auto_archive_duration;
/**
* The ID of the last message sent in this thread, if one was sent
* @type {?Snowflake}
*/
this.lastMessageID = data.last_message_id;
/**
* The timestamp when the last pinned message was pinned, if there was one
* @type {?number}
*/
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
/**
* The ratelimit per user for this thread in seconds
* @type {number}
*/
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
/** /**
* The timestamp when the thread's archive status was last changed * The timestamp when the thread's archive status was last changed
* <info>If the thread was never archived or unarchived, this is set when it's created</info> * <info>If the thread was never archived or unarchived, this is set when it's created</info>
* @type {number} * @type {number}
*/ */
this.archiveTimestamp = new Date(data.thread_metadata.archive_timestamp).getTime(); this.archiveTimestamp = new Date(data.thread_metadata.archive_timestamp).getTime();
}
if ('owner_id' in data) {
/**
* The id of the member that created this thread
* @type {?Snowflake}
*/
this.ownerID = data.owner_id;
}
if ('last_message_id' in data) {
/**
* The ID of the last message sent in this thread, if one was sent
* @type {?Snowflake}
*/
this.lastMessageID = data.last_message_id;
}
if ('last_pin_timestamp' in data) {
/**
* The timestamp when the last pinned message was pinned, if there was one
* @type {?number}
*/
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
}
if ('rate_limit_per_user' in data) {
/**
* The ratelimit per user for this thread in seconds
* @type {number}
*/
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
}
if ('message_count' in data) {
/** /**
* The approximate count of messages in this thread * The approximate count of messages in this thread
* <info>This value will not count above 50 even when there are more than 50 messages * <info>This value will not count above 50 even when there are more than 50 messages
@@ -112,13 +125,16 @@ class ThreadChannel extends Channel {
* @type {number} * @type {number}
*/ */
this.messageCount = data.message_count; this.messageCount = data.message_count;
}
if ('member_count' in data) {
/** /**
* The approximate count of users in this thread * The approximate count of users in this thread
* <info>This value will not count above 50 even when there are more than 50 members</info> * <info>This value will not count above 50 even when there are more than 50 members</info>
* @type {number} * @type {number}
*/ */
this.memberCount = data.member_count; this.memberCount = data.member_count;
}
if (data.member && this.client.user) this.members._add({ user_id: this.client.user.id, ...data.member }); if (data.member && this.client.user) this.members._add({ user_id: this.client.user.id, ...data.member });
if (data.messages) for (const message of data.messages) this.messages.add(message); if (data.messages) for (const message of data.messages) this.messages.add(message);