diff --git a/src/api/chats.controller.ts b/src/api/chats.controller.ts index a2c7e287..82d573b5 100644 --- a/src/api/chats.controller.ts +++ b/src/api/chats.controller.ts @@ -124,6 +124,17 @@ class ChatsController { ) { return session.chatsUnarchiveChat(chatId); } + + @Post(':chatId/unread') + @SessionApiParam + @ChatIdApiParam + @ApiOperation({ summary: 'Unread the chat' }) + unreadChat( + @WorkingSessionParam session: WhatsappSession, + @Param('chatId') chatId: string, + ) { + return session.chatsUnreadChat(chatId); + } } export { ChatsController }; diff --git a/src/core/abc/session.abc.ts b/src/core/abc/session.abc.ts index c1ef1062..7a7a094b 100644 --- a/src/core/abc/session.abc.ts +++ b/src/core/abc/session.abc.ts @@ -359,6 +359,10 @@ export abstract class WhatsappSession { throw new NotImplementedByEngineError(); } + public chatsUnreadChat(chatId: string): Promise { + throw new NotImplementedByEngineError(); + } + /** * Labels methods */ diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index 0dd09ec4..8d0f7a70 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -833,6 +833,15 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { return this.chatsPutArchive(chatId, false); } + public async chatsUnreadChat(chatId: string): Promise { + const jid = toJID(chatId); + const messages = await this.store.getMessagesByJid(jid, 1); + return await this.sock.chatModify( + { markRead: false, lastMessages: messages }, + jid, + ); + } + /** * Labels methods */ diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 7c63b4f6..bc7efe5a 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -566,6 +566,11 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { return this.whatsapp.unarchiveChat(id); } + public chatsUnreadChat(chatId: string): Promise { + const id = this.ensureSuffix(chatId); + return this.whatsapp.markChatUnread(id); + } + /** * * Label methods diff --git a/yarn.lock b/yarn.lock index 33116f7a..8c4ea946 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,7 +7,7 @@ __metadata: "@adiwajshing/baileys@github:devlikeapro/Baileys#fork-master-channels-678": version: 6.7.8 - resolution: "@adiwajshing/baileys@https://github.com/devlikeapro/Baileys.git#commit=d0323b92eb8365e6f32a61e41dd00010602d07f1" + resolution: "@adiwajshing/baileys@https://github.com/devlikeapro/Baileys.git#commit=fce71396d7a9229a23299b49d6e5bdca66e1c78b" dependencies: "@adiwajshing/keyed-db": ^0.2.4 "@hapi/boom": ^9.1.3 @@ -39,7 +39,7 @@ __metadata: optional: true sharp: optional: true - checksum: a3b461006443713074401a17c3481aef571301e83f1fba193d06e7f9ea4c47359b5c973d0b3804e34d4e48c35bdc1a64d8c3e59a0a744e5bc9bcca591d180901 + checksum: c8823494b7d7d237c32eeac2fdd09a1345bb4e16cd11de28dc326909778dc8c7f9ea4231af86659a8fa04231720709798b7ed7b070b555c67ec4dce77d4e064a languageName: node linkType: hard