Allow a chat to be muted indefinitely (#849)

* muteChat fixed

* Update src/Client.js

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>

* Update src/Client.js

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>

* date fix

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
This commit is contained in:
Rajeh Taher
2021-10-30 06:24:36 +03:00
committed by GitHub
parent 4338664590
commit 06107af67d
3 changed files with 12 additions and 11 deletions

10
index.d.ts vendored
View File

@@ -94,11 +94,11 @@ declare namespace WAWebJS {
getNumberId(number: string): Promise<ContactId | null> getNumberId(number: string): Promise<ContactId | null>
/** /**
* 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 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<void> muteChat(chatId: string, unmuteDate?: Date): Promise<void>
/** Force reset of connection state for the client */ /** Force reset of connection state for the client */
resetState(): Promise<void> resetState(): Promise<void>
@@ -867,8 +867,8 @@ declare namespace WAWebJS {
delete: () => Promise<boolean>, delete: () => Promise<boolean>,
/** Loads chat messages, sorted from earliest to latest. */ /** Loads chat messages, sorted from earliest to latest. */
fetchMessages: (searchOptions: MessageSearchOptions) => Promise<Message[]>, fetchMessages: (searchOptions: MessageSearchOptions) => Promise<Message[]>,
/** Mutes this chat until a specified date */ /** Mutes this chat forever, unless a date is specified */
mute: (unmuteDate: Date) => Promise<void>, mute: (unmuteDate?: Date) => Promise<void>,
/** Send a message to this chat */ /** Send a message to this chat */
sendMessage: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>, sendMessage: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
/** Set the message as seen */ /** Set the message as seen */

View File

@@ -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 {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) { async muteChat(chatId, unmuteDate) {
unmuteDate = unmuteDate ? unmuteDate.getTime() / 1000 : -1;
await this.pupPage.evaluate(async (chatId, timestamp) => { await this.pupPage.evaluate(async (chatId, timestamp) => {
let chat = await window.Store.Chat.get(chatId); let chat = await window.Store.Chat.get(chatId);
await chat.mute.mute(timestamp, !0); await chat.mute.mute(timestamp, !0);
}, chatId, unmuteDate.getTime() / 1000); }, chatId, unmuteDate || -1);
} }
/** /**

View File

@@ -147,10 +147,10 @@ class Chat extends Base {
} }
/** /**
* Mutes this chat until a specified date * Mutes this chat forever, unless a date is specified
* @param {Date} unmuteDate Date at which the Chat will be unmuted * @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); return this.client.muteChat(this.id._serialized, unmuteDate);
} }