Skip to content

Commit

Permalink
Merge pull request #2809 from ghayman/master
Browse files Browse the repository at this point in the history
Fixed getGroupParticipant() to stop it cancelling the message Unread notification badges
  • Loading branch information
ghayman authored Nov 10, 2024
2 parents e633f8d + daed3d3 commit 8f846c9
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 56 deletions.
86 changes: 86 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* eslint-disable */
const venom = require('./dist/index');

try {
venom
.create({
session: 'sessionName_0001',
headless: false,
devtools: true,
useChrome: false,
})
.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());
const hostData = await client.getHost();
if(hostData && hostData.id) {
console.log(hostData.id);
}


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.onStateChange((state) => {
console.log("State change: " + client.session);
console.log("State change: " + state);
})

client.onStreamChange((stream) => {
console.log("Stream change: " + client.session);
console.log("Stream change: " + stream);
})

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);
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/layers/group.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/api/layers/host.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ export class HostLayer {
return await this.page.evaluate(() => WAPI.isLoggedIn());
}

/**
* Retrieves information about the host including who is logged in
*/
public async getHost() {
return await this.page.evaluate(() => WAPI.getHost());
}

/**
* Retrieves Battery Level
*/
Expand Down
11 changes: 8 additions & 3 deletions src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ export const getInterfaceStatus = async (waPage: puppeteer.Page) => {
if (erroHTTP && erroHTTP[0].innerText.includes('HTTP ERROR 429')) {
return { type: erroHTTP[0].innerText };
}
const elLoginWrapper = document.querySelector(
const elLoginWrapper1 = document.querySelector(
'body > div > div > .landing-wrapper'
);
const elLoginWrapper2 = document.querySelector(
'body > div > div > div > .landing-wrapper'
);
const elLoginWrapper3 = document.querySelector(
'body > div > div > div > div > div > .x1lliihq'
);

const elQRCodeCanvas = document.querySelector('canvas');
if (
(elLoginWrapper && elQRCodeCanvas) ||
(elLoginWrapper2 && elQRCodeCanvas)
(elLoginWrapper1 && elQRCodeCanvas) ||
(elLoginWrapper2 && elQRCodeCanvas) ||
(elLoginWrapper3 && elQRCodeCanvas)
) {
return 'UNPAIRED';
}
Expand Down
99 changes: 47 additions & 52 deletions src/lib/wapi/functions/get-group-participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

0 comments on commit 8f846c9

Please sign in to comment.