fix: Client.createGroup + GroupChat.addParticipants (#3670)

* Adjustment addParticipants

* createGroup fully refactored, fixed bugs, added creation options and updated docs

* fix: eslint fix

* refactor: GroupChat.addParticipants fully refactored

* fix: eslint fix

---------

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

View file

@ -1528,6 +1528,10 @@ class Client extends EventEmitter {
* @property {string|undefined} parentGroupId The ID of a parent community group to link the newly created group with (won't take an effect if the group is been creating with myself only)
* @property {boolean} [autoSendInviteV4 = true] If true, the inviteV4 will be sent to those participants who have restricted others from being automatically added to groups, otherwise the inviteV4 won't be sent (true by default)
* @property {string} [comment = ''] The comment to be added to an inviteV4 (empty string by default)
* @property {boolean} [memberAddMode = false] If true, only admins can add members to the group (false by default)
* @property {boolean} [membershipApprovalMode = false] If true, group admins will be required to approve anyone who wishes to join the group (false by default)
* @property {boolean} [isRestrict = true] If true, only admins can change group group info (true by default)
* @property {boolean} [isAnnounce = false] If true, only admins can send messages (false by default)
*/
/**
@ -1542,7 +1546,12 @@ class Client extends EventEmitter {
participants.map(p => (p instanceof Contact) ? p.id._serialized : p);
return await this.pupPage.evaluate(async (title, participants, options) => {
const { messageTimer = 0, parentGroupId, autoSendInviteV4 = true, comment = '' } = options;
const {
messageTimer = 0,
parentGroupId,
autoSendInviteV4 = true,
comment = '',
} = options;
const participantData = {}, participantWids = [], failedParticipants = [];
let createGroupResult, parentGroupWid;
@ -1555,7 +1564,9 @@ class Client extends EventEmitter {
for (const participant of participants) {
const pWid = window.Store.WidFactory.createWid(participant);
if ((await window.Store.QueryExist(pWid))?.wid) participantWids.push(pWid);
if ((await window.Store.QueryExist(pWid))?.wid) {
participantWids.push({ phoneNumber: pWid });
}
else failedParticipants.push(participant);
}
@ -1564,14 +1575,13 @@ class Client extends EventEmitter {
try {
createGroupResult = await window.Store.GroupUtils.createGroup(
{
'memberAddMode': options.memberAddMode === undefined ? true : options.memberAddMode,
'membershipApprovalMode': options.membershipApprovalMode === undefined ? false : options.membershipApprovalMode,
'announce': options.announce === undefined ? true : options.announce,
'addressingModeOverride': 'lid',
'memberAddMode': options.memberAddMode ?? false,
'membershipApprovalMode': options.membershipApprovalMode ?? false,
'announce': options.announce ?? false,
'restrict': options.isRestrict !== undefined ? !options.isRestrict : false,
'ephemeralDuration': messageTimer,
'full': undefined,
'parentGroupId': parentGroupWid,
'restrict': options.restrict === undefined ? true : options.restrict,
'thumb': undefined,
'title': title,
},
participantWids
@ -1582,13 +1592,14 @@ class Client extends EventEmitter {
for (const participant of createGroupResult.participants) {
let isInviteV4Sent = false;
participant.wid.server == 'lid' && (participant.wid = window.Store.LidUtils.getPhoneNumber(participant.wid));
const participantId = participant.wid._serialized;
const statusCode = participant.error || 200;
if (autoSendInviteV4 && statusCode === 403) {
window.Store.Contact.gadd(participant.wid, { silent: true });
const addParticipantResult = await window.Store.GroupInviteV4.sendGroupInviteMessage(
await window.Store.Chat.find(participant.wid),
window.Store.Chat.get(participant.wid) || await window.Store.Chat.find(participant.wid),
createGroupResult.wid._serialized,
createGroupResult.subject,
participant.invite_code,
@ -1596,9 +1607,7 @@ class Client extends EventEmitter {
comment,
await window.WWebJS.getProfilePicThumbToBase64(createGroupResult.wid)
);
isInviteV4Sent = window.compareWwebVersions(window.Debug.VERSION, '<', '2.2335.6')
? addParticipantResult === 'OK'
: addParticipantResult.messageSendResult === 'OK';
isInviteV4Sent = addParticipantResult.messageSendResult === 'OK';
}
participantData[participantId] = {