From bf2775d1f003f4fa652e19a8fd4b0d93b467123e Mon Sep 17 00:00:00 2001 From: "Pedro S. Lopez" Date: Sun, 11 Oct 2020 15:14:06 -0400 Subject: [PATCH] feat: update group settings (messages and set info admins only) (#374) close #187 --- src/structures/GroupChat.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index 8fc95cc..988c5c9 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -35,6 +35,7 @@ class GroupChat extends Chat { get description() { return this.groupMetadata.desc; } + /** * Gets the group participants * @type {array} @@ -112,6 +113,38 @@ class GroupChat extends Chat { } } + /** + * 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. + */ + async setMessagesAdminsOnly(adminsOnly=true) { + let res = await this.client.pupPage.evaluate((chatId, value) => { + return window.Store.Wap.setGroupProperty(chatId, 'announcement', value); + }, this.id._serialized, adminsOnly); + + if (res.status !== 200) return false; + + this.groupMetadata.announce = adminsOnly; + return true; + } + + /** + * Updates the group settings to only allow admins to edit group info (title, description, photo). + * @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 setInfoAdminsOnly(adminsOnly=true) { + let res = await this.client.pupPage.evaluate((chatId, value) => { + return window.Store.Wap.setGroupProperty(chatId, 'restrict', value); + }, this.id._serialized, adminsOnly); + + if (res.status !== 200) return false; + + this.groupMetadata.restrict = adminsOnly; + return true; + } + /** * Gets the invite code for a specific group */