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,75 +50,91 @@ 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 /**
* @type {Snowflake} * The ID of the parent channel to this thread
*/ * @type {Snowflake}
this.parentID = data.parent_id; */
this.parentID = data.parent_id;
}
/** if ('thread_metadata' in data) {
* Whether the thread is locked /**
* @type {boolean} * Whether the thread is locked
*/ * @type {boolean}
this.locked = data.thread_metadata.locked ?? false; */
this.locked = data.thread_metadata.locked ?? false;
/** /**
* Whether the thread is active (false) or archived (true) * Whether the thread is active (false) or archived (true)
* @type {boolean} * @type {boolean}
*/ */
this.archived = data.thread_metadata.archived; this.archived = data.thread_metadata.archived;
/** /**
* The id of the member that created this thread * How long in minutes after recent activity before the thread is automatically archived
* @type {?Snowflake} * @type {number}
*/ */
this.ownerID = data.owner_id; this.autoArchiveDuration = data.thread_metadata.auto_archive_duration;
/** /**
* How long in minutes after recent activity before the thread is automatically archived * The timestamp when the thread's archive status was last changed
* @type {number} * <info>If the thread was never archived or unarchived, this is set when it's created</info>
*/ * @type {number}
this.autoArchiveDuration = data.thread_metadata.auto_archive_duration; */
this.archiveTimestamp = new Date(data.thread_metadata.archive_timestamp).getTime();
}
/** if ('owner_id' in data) {
* The ID of the last message sent in this thread, if one was sent /**
* @type {?Snowflake} * The id of the member that created this thread
*/ * @type {?Snowflake}
this.lastMessageID = data.last_message_id; */
this.ownerID = data.owner_id;
}
/** if ('last_message_id' in data) {
* The timestamp when the last pinned message was pinned, if there was one /**
* @type {?number} * The ID of the last message sent in this thread, if one was sent
*/ * @type {?Snowflake}
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null; */
this.lastMessageID = data.last_message_id;
}
/** if ('last_pin_timestamp' in data) {
* The ratelimit per user for this thread in seconds /**
* @type {number} * The timestamp when the last pinned message was pinned, if there was one
*/ * @type {?number}
this.rateLimitPerUser = data.rate_limit_per_user ?? 0; */
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
}
/** if ('rate_limit_per_user' in data) {
* 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> * The ratelimit per user for this thread in seconds
* @type {number} * @type {number}
*/ */
this.archiveTimestamp = new Date(data.thread_metadata.archive_timestamp).getTime(); this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
}
/** if ('message_count' in data) {
* The approximate count of messages in this thread /**
* <info>This value will not count above 50 even when there are more than 50 messages * The approximate count of messages in this thread
* If you need an approximate value higher than this, use ThreadChannel#messages.cache.size</info> * <info>This value will not count above 50 even when there are more than 50 messages
* @type {number} * If you need an approximate value higher than this, use ThreadChannel#messages.cache.size</info>
*/ * @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 /**
* <info>This value will not count above 50 even when there are more than 50 members</info> * The approximate count of users in this thread
* @type {number} * <info>This value will not count above 50 even when there are more than 50 members</info>
*/ * @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);