Skip to content

Commit

Permalink
fix: correct permissions checks and cache on update (#6015)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckohen committed Jul 3, 2021
1 parent 4adfc45 commit 568691c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/client/actions/ChannelUpdate.js
Expand Up @@ -24,6 +24,8 @@ class ChannelUpdateAction extends Action {
old,
updated: channel,
};
} else {
client.channels.add(data);
}

return {};
Expand Down
2 changes: 1 addition & 1 deletion src/managers/ThreadMemberManager.js
Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion src/structures/ThreadChannel.js
Expand Up @@ -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;
}

/**
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -1982,6 +1982,7 @@ declare module 'discord.js' {
public guild: Guild;
public readonly guildMembers: Collection<Snowflake, GuildMember>;
public readonly joinable: boolean;
public readonly joined: boolean;
public locked: boolean;
public readonly manageable: boolean;
public readonly sendable: boolean;
Expand Down

0 comments on commit 568691c

Please sign in to comment.