From 68eacc1171aef625c302906d63f63e1b82318a83 Mon Sep 17 00:00:00 2001 From: sdanialraza Date: Sat, 18 May 2024 16:12:15 +0200 Subject: [PATCH 1/5] feat(Message): add `call` --- packages/discord.js/src/structures/Message.js | 22 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 6 +++++ 2 files changed, 28 insertions(+) diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index bbd550cc21f7..3df2e3174edf 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -417,6 +417,28 @@ class Message extends Base { } else { this.poll ??= null; } + + /** + * The call associated with the message + * @typedef {Object} MessageCall + * @property {?Date} endedAt The time the call ended + * @property {?number} endedTimestamp The timestamp the call ended + * @property {Snowflake[]} participants The ids of the users that participated in the call + */ + + if (data.call) { + /** + * The call associated with the message + * @type {?MessageCall} + */ + this.call = { + endedAt: data.call.ended_timestamp && new Date(data.call.ended_timestamp), + endedTimestamp: data.call.ended_timestamp && Date.parse(data.call.ended_timestamp), + participants: data.call.participants, + }; + } else { + this.call ??= null; + } } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 8dd053843780..0c590abc85bb 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2027,6 +2027,12 @@ export class LimitedCollection extends Collection { public keepOverLimit: ((value: Value, key: Key, collection: this) => boolean) | null; } +export interface MessageCall { + endedAt: Date | null; + endedTimestamp: number | null; + participants: readonly Snowflake[]; +} + export type MessageComponentType = Exclude; export interface MessageCollectorOptionsParams< From 987170867299b11fb65c3714c8f146fa15a2a857 Mon Sep 17 00:00:00 2001 From: sdanialraza Date: Mon, 20 May 2024 16:21:07 +0200 Subject: [PATCH 2/5] refactor: make `endedAt` a getter --- packages/discord.js/src/structures/Message.js | 6 ++++-- packages/discord.js/typings/index.d.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 3df2e3174edf..7ddd2fd25ca4 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -421,7 +421,7 @@ class Message extends Base { /** * The call associated with the message * @typedef {Object} MessageCall - * @property {?Date} endedAt The time the call ended + * @property {?Readonly} endedAt The time the call ended * @property {?number} endedTimestamp The timestamp the call ended * @property {Snowflake[]} participants The ids of the users that participated in the call */ @@ -432,9 +432,11 @@ class Message extends Base { * @type {?MessageCall} */ this.call = { - endedAt: data.call.ended_timestamp && new Date(data.call.ended_timestamp), endedTimestamp: data.call.ended_timestamp && Date.parse(data.call.ended_timestamp), participants: data.call.participants, + get endedAt() { + return this.endedTimestamp && new Date(this.endedTimestamp); + }, }; } else { this.call ??= null; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 0c590abc85bb..6deaa0270045 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2028,7 +2028,7 @@ export class LimitedCollection extends Collection { } export interface MessageCall { - endedAt: Date | null; + get endedAt(): Readonly | null; endedTimestamp: number | null; participants: readonly Snowflake[]; } From bbd632e50dd4305a5ba49005db44cae2d5b67c4f Mon Sep 17 00:00:00 2001 From: sdanialraza Date: Tue, 21 May 2024 09:47:04 +0200 Subject: [PATCH 3/5] types: fix `endedAt` return type --- packages/discord.js/typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 6deaa0270045..d027be05b1dc 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2028,7 +2028,7 @@ export class LimitedCollection extends Collection { } export interface MessageCall { - get endedAt(): Readonly | null; + get endedAt(): Date | null; endedTimestamp: number | null; participants: readonly Snowflake[]; } From 4655cd276f28d7eb9dd92dae54fc2c4895d6d90c Mon Sep 17 00:00:00 2001 From: sdanialraza Date: Sun, 2 Jun 2024 23:42:38 +0200 Subject: [PATCH 4/5] types(Message): add `call` property --- packages/discord.js/typings/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index d027be05b1dc..ad28287fc1d1 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2124,6 +2124,7 @@ export class Message extends Base { public get thread(): AnyThreadChannel | null; public tts: boolean; public poll: Poll | null; + public call: MessageCall | null; public type: MessageType; public get url(): string; public webhookId: Snowflake | null; From d2452338e70354a07d502e390b77ed199eff7b34 Mon Sep 17 00:00:00 2001 From: sdanialraza Date: Wed, 5 Jun 2024 14:16:42 +0200 Subject: [PATCH 5/5] docs: requested changes --- packages/discord.js/src/structures/Message.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 7ddd2fd25ca4..54c279591716 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -419,9 +419,9 @@ class Message extends Base { } /** - * The call associated with the message + * A call associated with a message * @typedef {Object} MessageCall - * @property {?Readonly} endedAt The time the call ended + * @property {Readonly} endedAt The time the call ended * @property {?number} endedTimestamp The timestamp the call ended * @property {Snowflake[]} participants The ids of the users that participated in the call */ @@ -432,7 +432,7 @@ class Message extends Base { * @type {?MessageCall} */ this.call = { - endedTimestamp: data.call.ended_timestamp && Date.parse(data.call.ended_timestamp), + endedTimestamp: data.call.ended_timestamp ? Date.parse(data.call.ended_timestamp) : null, participants: data.call.participants, get endedAt() { return this.endedTimestamp && new Date(this.endedTimestamp);