diff --git a/index.d.ts b/index.d.ts index 329a419..6c1f703 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1523,6 +1523,12 @@ declare namespace WAWebJS { setSubject: (subject: string) => Promise; /** Updates the group description */ setDescription: (description: string) => Promise; + /** + * 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} 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; /** Updates the group settings to only allow admins to send messages * @param {boolean} [adminsOnly=true] Enable or disable this option * @returns {Promise} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions. diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index d974f9d..4ae5b19 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -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} 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