diff --git a/index.d.ts b/index.d.ts index cebbb75..b16a20f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -223,6 +223,12 @@ declare namespace WAWebJS { /** The new ACK value */ ack: MessageAck ) => void): this + + /** Emitted when a chat unread count changes */ + on(event: 'unread_count', listener: ( + /** The chat that was affected */ + chat: Chat + ) => void): this /** Emitted when a new message is created, which may include the current user's own messages */ on(event: 'message_create', listener: ( diff --git a/src/Client.js b/src/Client.js index 955aadc..acd04ac 100644 --- a/src/Client.js +++ b/src/Client.js @@ -407,6 +407,15 @@ class Client extends EventEmitter { }); + await page.exposeFunction('onChatUnreadCountEvent', async (data) =>{ + const chat = await this.getChatById(data.id); + + /** + * Emitted when the chat unread count changes + */ + this.emit(Events.UNREAD_COUNT, chat); + }); + await page.exposeFunction('onMessageMediaUploadedEvent', (msg) => { const message = new Message(this, msg); @@ -526,7 +535,8 @@ class Client extends EventEmitter { } } }); - + window.Store.Chat.on('change:unreadCount', (chat) => {window.onChatUnreadCountEvent(chat);}); + { const module = window.Store.createOrUpdateReactionsModule; const ogMethod = module.createOrUpdateReactions; diff --git a/src/util/Constants.js b/src/util/Constants.js index 4c22fa1..e341b4c 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -41,6 +41,7 @@ exports.Events = { MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone', MESSAGE_REVOKED_ME: 'message_revoke_me', MESSAGE_ACK: 'message_ack', + UNREAD_COUNT: 'unread_count', MESSAGE_REACTION: 'message_reaction', MEDIA_UPLOADED: 'media_uploaded', GROUP_JOIN: 'group_join',