From 06107af67d191b0c74c2ceab2fe4e72a7e7cc075 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Oct 2021 06:24:36 +0300 Subject: [PATCH] Allow a chat to be muted indefinitely (#849) * muteChat fixed * Update src/Client.js Co-authored-by: Pedro S. Lopez * Update src/Client.js Co-authored-by: Pedro S. Lopez * date fix Co-authored-by: Pedro S. Lopez --- index.d.ts | 10 +++++----- src/Client.js | 7 ++++--- src/structures/Chat.js | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index cc82a26..d4fedc5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -94,11 +94,11 @@ declare namespace WAWebJS { getNumberId(number: string): Promise /** - * Mutes the Chat until a specified date + * Mutes this chat forever, unless a date is specified * @param chatId ID of the chat that will be muted - * @param unmuteDate Date when the chat will be unmuted + * @param unmuteDate Date when the chat will be unmuted, leave as is to mute forever */ - muteChat(chatId: string, unmuteDate: Date): Promise + muteChat(chatId: string, unmuteDate?: Date): Promise /** Force reset of connection state for the client */ resetState(): Promise @@ -867,8 +867,8 @@ declare namespace WAWebJS { delete: () => Promise, /** Loads chat messages, sorted from earliest to latest. */ fetchMessages: (searchOptions: MessageSearchOptions) => Promise, - /** Mutes this chat until a specified date */ - mute: (unmuteDate: Date) => Promise, + /** Mutes this chat forever, unless a date is specified */ + mute: (unmuteDate?: Date) => Promise, /** Send a message to this chat */ sendMessage: (content: MessageContent, options?: MessageSendOptions) => Promise, /** Set the message as seen */ diff --git a/src/Client.js b/src/Client.js index 11a5e1e..afb8b2f 100644 --- a/src/Client.js +++ b/src/Client.js @@ -765,15 +765,16 @@ class Client extends EventEmitter { } /** - * Mutes the Chat until a specified date + * Mutes this chat forever, unless a date is specified * @param {string} chatId ID of the chat that will be muted - * @param {Date} unmuteDate Date when the chat will be unmuted + * @param {?Date} unmuteDate Date when the chat will be unmuted, leave as is to mute forever */ async muteChat(chatId, unmuteDate) { + unmuteDate = unmuteDate ? unmuteDate.getTime() / 1000 : -1; await this.pupPage.evaluate(async (chatId, timestamp) => { let chat = await window.Store.Chat.get(chatId); await chat.mute.mute(timestamp, !0); - }, chatId, unmuteDate.getTime() / 1000); + }, chatId, unmuteDate || -1); } /** diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 056ddaf..26d168b 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -147,10 +147,10 @@ class Chat extends Base { } /** - * Mutes this chat until a specified date - * @param {Date} unmuteDate Date at which the Chat will be unmuted + * Mutes this chat forever, unless a date is specified + * @param {?Date} unmuteDate Date at which the Chat will be unmuted, leave as is to mute forever */ - async mute(unmuteDate) { + async mute(unmuteDate = undefined) { return this.client.muteChat(this.id._serialized, unmuteDate); }