From 17be91b63ca329cd41aabc10d4bd78a83fdfb865 Mon Sep 17 00:00:00 2001 From: Geoff Hayman Date: Tue, 10 Sep 2024 15:12:06 -0700 Subject: [PATCH] Fixed getGroupParticipant() to stop it cancelling the message Unread notification badges --- app.js | 70 +++++++++++++ package.json | 1 + src/api/layers/group.layer.ts | 2 +- .../wapi/functions/get-group-participant.js | 99 +++++++++---------- 4 files changed, 119 insertions(+), 53 deletions(-) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 000000000..ff4b8667c --- /dev/null +++ b/app.js @@ -0,0 +1,70 @@ +/* eslint-disable */ +const venom = require('./dist/index'); + +try { + venom + .create({ + session: 'sessionName_0001', + headless: false, + devtools: true, + }) + .then((client) => start(client)) + .catch(async (err) => { + console.log('Startup error: ' + err); + }); +} catch (e) { + console.log(e); +} + +async function start(client) { + console.log('We have started'); + console.log(await client.getWAVersion()); + + const page = client.waPage; + const browser = page.browser(); + const pid = browser.process().pid; + + console.log(JSON.stringify(pid, null, 2)); + + console.log(await client.isLoggedIn()); + + let lastMessageId = ""; + + client.onAnyMessage((message) => { + if (lastMessageId === message.id) { + console.log('Duplicate message: ' + lastMessageId) + } else { + lastMessageId = message.id; + console.log(message); + console.log('New message: ' + message.id + ' ' + message.type); + } + + if (message['isGroupMsg']) { + const ids = client + .getGroupMembers(message['chatId'], 1000) + .then((ids) => { + console.log(ids); + }); + } + }); + + client.onMessageEdit((message) => { + console.log('EDIT!'); + console.log(message); + }); + + client.onMessageDelete((message) => { + console.log('DELETE!'); + console.log(message); + }); + + client.onMessageEdit((message) => { + console.log('EDIT!'); + console.log(message); + }); + + client.onMessageReaction((reaction) => { + console.log('REACTION!'); + console.log(reaction); + }); +} diff --git a/package.json b/package.json index 008b6b74b..3d7666da7 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "release": "release-it", "start": "npm run build:venom & tsc app.ts && node app.js", "test": "node ./test/index.js", + "test:app": "node ./app.js", "watch": "concurrently \"tsc -w\" \"nodemon dist/index.js\"" }, "husky": { diff --git a/src/api/layers/group.layer.ts b/src/api/layers/group.layer.ts index 3b19b3682..a565b07bd 100644 --- a/src/api/layers/group.layer.ts +++ b/src/api/layers/group.layer.ts @@ -266,7 +266,7 @@ export class GroupLayer extends RetrieverLayer { if (typeof validating === 'object') { return reject(validating); } - const result = this.page.evaluate( + const result = await this.page.evaluate( (groupId: string, time: string) => WAPI.getGroupParticipant(groupId, time), groupId, diff --git a/src/lib/wapi/functions/get-group-participant.js b/src/lib/wapi/functions/get-group-participant.js index fb601af2b..8c012cd1c 100644 --- a/src/lib/wapi/functions/get-group-participant.js +++ b/src/lib/wapi/functions/get-group-participant.js @@ -5,60 +5,55 @@ export async function getGroupParticipant(groupId, time = 1000) { return WAPI.scope(undefined, true, null, 'Use to groupId string'); } - const chat = await WAPI.sendExist(groupId); + const moduleGroup = await window.Store.GroupMetadata._models.filter( + (e) => e.id._serialized === groupId + ); - if (chat && chat.status != 404 && chat.id) { - const moduleGroup = await window.Store.GroupMetadata._models.filter( - (e) => e.id._serialized === groupId - ); + const participants = + moduleGroup.length && moduleGroup[0].participants + ? moduleGroup[0].participants + : undefined; - const participants = - moduleGroup.length && moduleGroup[0].participants - ? moduleGroup[0].participants - : undefined; + if (participants) { + const output = participants.map((participant) => { + return { + id: participant.id, + displayName: + participant.contact && participant.contact.displayName + ? participant.contact.displayName + : null, + mentionName: + participant.contact && participant.contact.mentionName + ? participant.contact.mentionName + : null, + notifyName: + participant.contact && participant.contact.notifyName + ? participant.contact.notifyName + : null, + isBusiness: + participant.contact && participant.contact.isBusiness + ? participant.contact.isBusiness + : null, + pushname: + participant.contact && participant.contact.pushname + ? participant.contact.pushname + : null, + isUser: + participant.contact && participant.contact.isUser + ? participant.contact.isUser + : null, + isMyContact: + participant.contact && participant.contact.isMyContact + ? participant.contact.isMyContact + : null, + isMe: + participant.contact && participant.contact.isMe + ? participant.contact.isMe + : null + }; + }); - if (participants) { - const output = participants.map((participant) => { - return { - id: participant.id, - displayName: - participant.contact && participant.contact.displayName - ? participant.contact.displayName - : null, - mentionName: - participant.contact && participant.contact.mentionName - ? participant.contact.mentionName - : null, - notifyName: - participant.contact && participant.contact.notifyName - ? participant.contact.notifyName - : null, - isBusiness: - participant.contact && participant.contact.isBusiness - ? participant.contact.isBusiness - : null, - pushname: - participant.contact && participant.contact.pushname - ? participant.contact.pushname - : null, - isUser: - participant.contact && participant.contact.isUser - ? participant.contact.isUser - : null, - isMyContact: - participant.contact && participant.contact.isMyContact - ? participant.contact.isMyContact - : null, - isMe: - participant.contact && participant.contact.isMe - ? participant.contact.isMe - : null - }; - }); - - return output; - } - return WAPI.scope(undefined, true, null, 'Error find Group'); + return output; } - return WAPI.scope(undefined, true, null, 'Group not found'); + return WAPI.scope(undefined, true, null, 'Error find Group'); }