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:
parent
aa26876a4b
commit
b99d28c5c6
1 changed files with 27 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue