From 674b1c83cd798c0e7c4c2cc9795f478573ae173b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3nalan=20de=20Lima?= Date: Fri, 12 Feb 2021 19:12:54 -0300 Subject: [PATCH] feat: Get new messages chat --- README.md | 7 ++++++- src/api/layers/retriever.layer.ts | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e7aacefa1..0212a143b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ **Grupo de Suporte do Venom em português do Brasil | R$ 30 Mensais**

- ## 🕷🕷 Functions Venom🕷🕷 | | | @@ -569,6 +568,12 @@ await client.setChatState('000000000000@c.us', 0 | 1 | 2); ## Retrieving Data ```javascript +//Retrieve all contacts new messages +const ContactNewMsg = await client.getChatContactNewMsg(); + +//Retrieve all groups new messages +const GroupNewMsg = await client.getChatGroupNewMsg(); + // Returns a list of mute and non-mute users // "all" List all mutes // "toMute" List all silent chats diff --git a/src/api/layers/retriever.layer.ts b/src/api/layers/retriever.layer.ts index da80fbb9e..7fbfb97d6 100644 --- a/src/api/layers/retriever.layer.ts +++ b/src/api/layers/retriever.layer.ts @@ -143,18 +143,23 @@ export class RetrieverLayer extends SenderLayer { } /** - * Retrieve all groups + * Retrieve all groups new messages * @returns array of groups */ - public async getAllGroups(withNewMessagesOnly = false) { - if (withNewMessagesOnly) { - // prettier-ignore - const chats = await this.page.evaluate(() => WAPI.getAllChatsWithNewMsg()); - return chats.filter((chat) => chat.isGroup); - } else { - const chats = await this.page.evaluate(() => WAPI.getAllChats()); - return chats.filter((chat) => chat.isGroup); - } + public async getChatGroupNewMsg() { + // prettier-ignore + const chats = await this.page.evaluate(() => WAPI.getAllChatsWithNewMsg()); + return chats.filter((chat) => chat.kind === 'group'); + } + + /** + * Retrieve all contact new messages + * @returns array of groups + */ + public async getChatContactNewMsg() { + // prettier-ignore + const chats = await this.page.evaluate(() => WAPI.getAllChatsWithNewMsg()); + return chats.filter((chat) => chat.kind === 'chat'); } /**