Skip to content

Commit

Permalink
feat(ThreadChannel): add ThreadChannel#viewable (#6975)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Nov 18, 2021
1 parent 0c5c721 commit db09d79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/structures/Message.js
Expand Up @@ -551,7 +551,15 @@ class Message extends Base {
* @readonly
*/
get editable() {
return Boolean(this.author.id === this.client.user.id && !this.deleted && (!this.guild || this.channel?.viewable));
const precheck = Boolean(
this.author.id === this.client.user.id && !this.deleted && (!this.guild || this.channel?.viewable),
);
// Regardless of permissions thread messages cannot be edited if
// the thread is locked.
if (this.channel?.isThread()) {
return precheck && !this.channel.locked;
}
return precheck;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/structures/ThreadChannel.js
Expand Up @@ -442,6 +442,18 @@ class ThreadChannel extends Channel {
return this.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_THREADS, false);
}

/**
* Whether the thread is viewable by the client user
* @type {boolean}
* @readonly
*/
get viewable() {
if (this.client.user.id === this.guild.ownerId) return true;
const permissions = this.permissionsFor(this.client.user);
if (!permissions) return false;
return permissions.has(Permissions.FLAGS.VIEW_CHANNEL, false);
}

/**
* Whether the client user can send messages in this thread
* @type {boolean}
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -2099,6 +2099,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public readonly joined: boolean;
public locked: boolean | null;
public readonly manageable: boolean;
public readonly viewable: boolean;
public readonly sendable: boolean;
public memberCount: number | null;
public messageCount: number | null;
Expand Down

0 comments on commit db09d79

Please sign in to comment.