From 3e32fe27eaa6b25b162180d90141caa0fd65df38 Mon Sep 17 00:00:00 2001 From: Raphael R Date: Mon, 28 Dec 2020 21:03:01 -0300 Subject: [PATCH] feat: mark chat as unread (#475) Co-authored-by: Pedro S. Lopez --- index.d.ts | 5 +++++ src/Client.js | 11 +++++++++++ src/structures/Chat.js | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/index.d.ts b/index.d.ts index 5525d1d..5c24afb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -99,6 +99,9 @@ declare namespace WAWebJS { /** Mark as seen for the Chat */ sendSeen(chatId: string): Promise + /** Mark the Chat as unread */ + markChatUnread(chatId: string): Promise + /** * Sets the current user's status message * @param status New status message @@ -777,6 +780,8 @@ declare namespace WAWebJS { unmute: () => Promise, /** Returns the Contact that corresponds to this Chat. */ getContact: () => Promise, + /** Marks this Chat as unread */ + markUnread: () => Promise /** Returns array of all Labels assigned to this Chat */ getLabels: () => Promise } diff --git a/src/Client.js b/src/Client.js index 37c3962..1885b24 100644 --- a/src/Client.js +++ b/src/Client.js @@ -689,6 +689,17 @@ class Client extends EventEmitter { }, chatId); } + /** + * Mark the Chat as unread + * @param {string} chatId ID of the chat that will be marked as unread + */ + async markChatUnread(chatId) { + await this.pupPage.evaluate(async chatId => { + let chat = await window.Store.Chat.get(chatId); + await window.Store.Cmd.markChatUnread(chat, true); + }, chatId); + } + /** * Returns the contact ID's profile picture URL, if privacy settings allow it * @param {string} contactId the whatsapp user's ID diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 18eef54..056ddaf 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -161,6 +161,13 @@ class Chat extends Base { return this.client.unmuteChat(this.id._serialized); } + /** + * Mark this chat as unread + */ + async markUnread(){ + return this.client.markChatUnread(this.id._serialized); + } + /** * Loads chat messages, sorted from earliest to latest. * @param {Object} searchOptions Options for searching messages. Right now only limit is supported.