Skip to content

Commit

Permalink
fix(thread): don't assign directly to getters (#7346)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Jan 26, 2022
1 parent 9a566e8 commit 2db0cdd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 13 additions & 7 deletions packages/discord.js/src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,8 @@ class ThreadChannel extends Channel {
this.archiveTimestamp = Date.parse(data.thread_metadata.archive_timestamp);

if ('create_timestamp' in data.thread_metadata) {
/**
* The timestamp when this thread was created. This isn't available for threads
* created before 2022-01-09
* @type {?number}
*/
this.createdTimestamp = Date.parse(data.thread_metadata.create_timestamp);
// Note: this is needed because we can't assign directly to getters
this._createdTimestamp = Date.parse(data.thread_metadata.create_timestamp);
}
} else {
this.locked ??= null;
Expand All @@ -118,7 +114,7 @@ class ThreadChannel extends Channel {
this.invitable ??= null;
}

this.createdTimestamp ??= this.type === ChannelType.GuildPrivateThread ? super.createdTimestamp : null;
this._createdTimestamp ??= this.type === ChannelType.GuildPrivateThread ? super.createdTimestamp : null;

if ('owner_id' in data) {
/**
Expand Down Expand Up @@ -188,6 +184,16 @@ class ThreadChannel extends Channel {
if (data.messages) for (const message of data.messages) this.messages._add(message);
}

/**
* The timestamp when this thread was created. This isn't available for threads
* created before 2022-01-09
* @type {?number}
* @readonly
*/
get createdTimestamp() {
return this._createdTimestamp;
}

/**
* A collection of associated guild member objects of this thread's members
* @type {Collection<Snowflake, GuildMember>}
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,8 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel) {
public readonly archivedAt: Date | null;
public archiveTimestamp: number | null;
public readonly createdAt: Date | null;
public createdTimestamp: number | null;
private _createdTimestamp: number | null;
public readonly createdTimestamp: number | null;
public autoArchiveDuration: ThreadAutoArchiveDuration | null;
public readonly editable: boolean;
public guild: Guild;
Expand Down

0 comments on commit 2db0cdd

Please sign in to comment.