Fix: Remove, Promote and Demote Participants (#3674)

* Fix: Remove, Promote and Demote Participants

* Adjust to convert @lid to phone

* Update src/structures/GroupChat.js

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

* Update src/structures/GroupChat.js

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

* Update src/structures/GroupChat.js

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
BenyFilho 2025-08-08 18:38:22 -03:00 • committed by GitHub
commit 6953a6a5d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -125,9 +125,10 @@ class GroupChat extends Chat {
return Math.floor(Math.random() * (sleep[1] - sleep[0] + 1)) + sleep[0]; return Math.floor(Math.random() * (sleep[1] - sleep[0] + 1)) + sleep[0];
}; };
for (const pWid of participantWids) { for (let pWid of participantWids) {
const pId = pWid._serialized; const pId = pWid._serialized;
pWid = pWid.server === 'lid' ? window.Store.LidUtils.getPhoneNumber(pWid) : pWid;
participantData[pId] = { participantData[pId] = {
code: undefined, code: undefined,
message: undefined, message: undefined,
@ -195,7 +196,10 @@ class GroupChat extends Chat {
return await this.client.pupPage.evaluate(async (chatId, participantIds) => { return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false }); const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
const participants = participantIds.map(p => { const participants = participantIds.map(p => {
return chat.groupMetadata.participants.get(p); const wid = window.Store.WidFactory.createWid(p);
const lid = wid.server!=='lid' ? window.Store.LidUtils.getCurrentLid(wid) : wid;
const phone = wid.server=='lid' ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
return chat.groupMetadata.participants.get(lid?._serialized) || chat.groupMetadata.participants.get(phone?._serialized);
}).filter(p => Boolean(p)); }).filter(p => Boolean(p));
await window.Store.GroupParticipants.removeParticipants(chat, participants); await window.Store.GroupParticipants.removeParticipants(chat, participants);
return { status: 200 }; return { status: 200 };
@ -211,7 +215,10 @@ class GroupChat extends Chat {
return await this.client.pupPage.evaluate(async (chatId, participantIds) => { return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false }); const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
const participants = participantIds.map(p => { const participants = participantIds.map(p => {
return chat.groupMetadata.participants.get(p); const wid = window.Store.WidFactory.createWid(p);
const lid = wid.server!=='lid' ? window.Store.LidUtils.getCurrentLid(wid) : wid;
const phone = wid.server=='lid' ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
return chat.groupMetadata.participants.get(lid?._serialized) || chat.groupMetadata.participants.get(phone?._serialized);
}).filter(p => Boolean(p)); }).filter(p => Boolean(p));
await window.Store.GroupParticipants.promoteParticipants(chat, participants); await window.Store.GroupParticipants.promoteParticipants(chat, participants);
return { status: 200 }; return { status: 200 };
@ -227,7 +234,10 @@ class GroupChat extends Chat {
return await this.client.pupPage.evaluate(async (chatId, participantIds) => { return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false }); const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
const participants = participantIds.map(p => { const participants = participantIds.map(p => {
return chat.groupMetadata.participants.get(p); const wid = window.Store.WidFactory.createWid(p);
const lid = wid.server!=='lid' ? window.Store.LidUtils.getCurrentLid(wid) : wid;
const phone = wid.server=='lid' ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
return chat.groupMetadata.participants.get(lid?._serialized) || chat.groupMetadata.participants.get(phone?._serialized);
}).filter(p => Boolean(p)); }).filter(p => Boolean(p));
await window.Store.GroupParticipants.demoteParticipants(chat, participants); await window.Store.GroupParticipants.demoteParticipants(chat, participants);
return { status: 200 }; return { status: 200 };