fix: enforce retrieval lid and phone for previously unknown contacts (#3702)

* fix: check existance if undefined

* fix: handle missing lid/phone in group participant resolution

* refactor: remove duplicated logic
This commit is contained in:
alechkos 2025-09-06 18:24:19 +03:00 • committed by GitHub
commit d077716315
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 28 deletions

View file

@ -195,12 +195,12 @@ class GroupChat extends Chat {
async removeParticipants(participantIds) {
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
const participants = participantIds.map(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));
const participants = (await Promise.all(participantIds.map(async p => {
const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
return chat.groupMetadata.participants.get(lid?._serialized) ||
chat.groupMetadata.participants.get(phone?._serialized);
}))).filter(Boolean);
await window.Store.GroupParticipants.removeParticipants(chat, participants);
return { status: 200 };
}, this.id._serialized, participantIds);
@ -214,12 +214,12 @@ class GroupChat extends Chat {
async promoteParticipants(participantIds) {
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
const participants = participantIds.map(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));
const participants = (await Promise.all(participantIds.map(async p => {
const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
return chat.groupMetadata.participants.get(lid?._serialized) ||
chat.groupMetadata.participants.get(phone?._serialized);
}))).filter(Boolean);
await window.Store.GroupParticipants.promoteParticipants(chat, participants);
return { status: 200 };
}, this.id._serialized, participantIds);
@ -233,12 +233,12 @@ class GroupChat extends Chat {
async demoteParticipants(participantIds) {
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
const participants = participantIds.map(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));
const participants = (await Promise.all(participantIds.map(async p => {
const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
return chat.groupMetadata.participants.get(lid?._serialized) ||
chat.groupMetadata.participants.get(phone?._serialized);
}))).filter(Boolean);
await window.Store.GroupParticipants.demoteParticipants(chat, participants);
return { status: 200 };
}, this.id._serialized, participantIds);