From 568691ce6a7994adc85db2b2a5b2227ece8c8358 Mon Sep 17 00:00:00 2001 From: ckohen Date: Sat, 3 Jul 2021 05:23:01 -0700 Subject: [PATCH] fix: correct permissions checks and cache on update (#6015) --- src/client/actions/ChannelUpdate.js | 2 ++ src/managers/ThreadMemberManager.js | 2 +- src/structures/ThreadChannel.js | 13 ++++++++++++- typings/index.d.ts | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/client/actions/ChannelUpdate.js b/src/client/actions/ChannelUpdate.js index 06bb71b85354..ac875a32d2d7 100644 --- a/src/client/actions/ChannelUpdate.js +++ b/src/client/actions/ChannelUpdate.js @@ -24,6 +24,8 @@ class ChannelUpdateAction extends Action { old, updated: channel, }; + } else { + client.channels.add(data); } return {}; diff --git a/src/managers/ThreadMemberManager.js b/src/managers/ThreadMemberManager.js index 524cd9fde2e1..d66e88f66c62 100644 --- a/src/managers/ThreadMemberManager.js +++ b/src/managers/ThreadMemberManager.js @@ -6,7 +6,7 @@ const ThreadMember = require('../structures/ThreadMember'); const Collection = require('../util/Collection'); /** - * Manages API methods for GuildMembers and stores their cache. + * Manages API methods for ThreadMembers and stores their cache. * @extends {BaseManager} */ class ThreadMemberManager extends BaseManager { diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js index a5fbf879e4b8..02d29109a763 100644 --- a/src/structures/ThreadChannel.js +++ b/src/structures/ThreadChannel.js @@ -297,13 +297,22 @@ class ThreadChannel extends Channel { return this.edit({ rateLimitPerUser }, reason); } + /** + * Whether the client user is a member of the thread. + * @type {boolean} + * @readonly + */ + get joined() { + return this.members.cache.has(this.client.user?.id); + } + /** * Whether the thread is editable by the client user (name, archived, autoArchiveDuration) * @type {boolean} * @readonly */ get editable() { - return this.ownerID === this.client.user.id || this.manageable; + return (this.ownerID === this.client.user.id && (this.type !== 'private_thread' || this.joined)) || this.manageable; } /** @@ -314,6 +323,7 @@ class ThreadChannel extends Channel { get joinable() { return ( !this.archived && + !this.joined && this.permissionsFor(this.client.user)?.has( this.type === 'private_thread' ? Permissions.FLAGS.MANAGE_THREADS : Permissions.FLAGS.VIEW_CHANNEL, false, @@ -338,6 +348,7 @@ class ThreadChannel extends Channel { get sendable() { return ( !this.archived && + (this.type !== 'private_thread' || this.joined || this.manageable) && this.permissionsFor(this.client.user)?.any( [ Permissions.FLAGS.SEND_MESSAGES, diff --git a/typings/index.d.ts b/typings/index.d.ts index d9cf42e7f5a8..4d7ce8c28e82 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1982,6 +1982,7 @@ declare module 'discord.js' { public guild: Guild; public readonly guildMembers: Collection; public readonly joinable: boolean; + public readonly joined: boolean; public locked: boolean; public readonly manageable: boolean; public readonly sendable: boolean;