Add members settings (#2788)

* Update GroupChat.js

* Update index.d.ts

* style: clarify method doc

* refactor: add additional check

* fix: provide valid error name

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
Gulg 2024-04-28 18:22:07 +05:00 • committed by GitHub
commit b99d28c5c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

6
index.d.ts vendored
View file

@ -1523,6 +1523,12 @@ declare namespace WAWebJS {
setSubject: (subject: string) => Promise<boolean>;
/** Updates the group description */
setDescription: (description: string) => Promise<boolean>;
/**
* Updates the group setting to allow only admins to add members to the group.
* @param {boolean} [adminsOnly=true] Enable or disable this option
* @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
*/
setAddMembersAdminsOnly: (adminsOnly?: boolean) => Promise<boolean>;
/** Updates the group settings to only allow admins to send messages
* @param {boolean} [adminsOnly=true] Enable or disable this option
* @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.

View file

@ -281,6 +281,27 @@ class GroupChat extends Chat {
return true;
}
/**
* Updates the group setting to allow only admins to add members to the group.
* @param {boolean} [adminsOnly=true] Enable or disable this option
* @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setAddMembersAdminsOnly(adminsOnly=true) {
const success = await this.client.pupPage.evaluate(async (groupId, adminsOnly) => {
const chatWid = window.Store.WidFactory.createWid(groupId);
try {
const response = await window.Store.GroupUtils.setGroupMemberAddMode(chatWid, 'member_add_mode', adminsOnly ? 0 : 1);
return response.name === 'SetMemberAddModeResponseSuccess';
} catch (err) {
if(err.name === 'SmaxParsingFailure') return false;
throw err;
}
}, this.id._serialized, adminsOnly);
success && (this.groupMetadata.memberAddMode = adminsOnly ? 'admin_add' : 'all_member_add');
return success;
}
/**
* Updates the group settings to only allow admins to send messages.
* @param {boolean} [adminsOnly=true] Enable or disable this option