From 2bef97e212edc56f2a86997f5aead3ab2ee9e4e8 Mon Sep 17 00:00:00 2001 From: alechkos Date: Wed, 27 Sep 2023 07:08:14 +0300 Subject: [PATCH] added deactivateCommunity method --- index.d.ts | 6 ++++++ src/Client.js | 18 ++++++++++++++++++ src/structures/Community.js | 19 ++++++++++--------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index ca08d0cada..52051c8a81 100644 --- a/index.d.ts +++ b/index.d.ts @@ -48,6 +48,9 @@ declare namespace WAWebJS { */ createCommunity(name: string, description: string, options: CreateCommunityOptions): Promise + /** Deactivates the community */ + deactivateCommunity: (parentGroupId: string) => Promise; + /** Closes the client */ destroy(): Promise @@ -1325,6 +1328,9 @@ declare namespace WAWebJS { /** Allows or disallows for non admin community members to add groups to the community */ setNonAdminSubGroupCreation: (value: boolean) => Promise; + + /** Deactivates the community */ + deactivate: () => Promise; } /** Create community options */ diff --git a/src/Client.js b/src/Client.js index 92f024434c..67d7b343bc 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1376,6 +1376,24 @@ class Client extends EventEmitter { }, name, description, options); } + /** + * Deactivates the community + * @param {string} parentGroupId The ID of a community parent group + * @returns {Promise} Returns true if the operation completed successfully, false otherwise + */ + async deactivateCommunity(parentGroupId) { + return await this.pupPage.evaluate(async (parentGroupId) => { + const communityWid = window.Store.WidFactory.createWid(parentGroupId); + try { + const response = await window.Store.CommunityUtils.sendDeactivateCommunity(communityWid); + return response ? true : false; + } catch (err) { + if (err.name === 'ServerStatusCodeError') return false; + throw err; + } + }, parentGroupId); + } + /** * Get all current Labels * @returns {Promise>} diff --git a/src/structures/Community.js b/src/structures/Community.js index 5f2f033446..5a5c7000d8 100644 --- a/src/structures/Community.js +++ b/src/structures/Community.js @@ -52,11 +52,7 @@ class Community extends GroupChat { async linkSubgroups(parentGroupId, subGroupIds) { return await this.client.pupPage.evaluate( async (parentGroupId, subGroupIds) => { - return await window.WWebJS.linkUnlinkSubgroups( - 'LinkSubgroups', - parentGroupId, - subGroupIds - ); + return await window.WWebJS.linkUnlinkSubgroups('LinkSubgroups', parentGroupId, subGroupIds); }, parentGroupId, subGroupIds @@ -103,10 +99,15 @@ class Community extends GroupChat { * @returns {Promise} Returns true if the operation completed successfully, false otherwise */ async setNonAdminSubGroupCreation(value = true) { - if (!this.groupMetadata.isParentGroup) return false; - const result = await this._setGroupProperty('allow_non_admin_sub_group_creation', value); - result && (this.groupMetadata.allowNonAdminSubGroupCreation = value); - return result; + return await this._setGroupProperty('allow_non_admin_sub_group_creation', value); + } + + /** + * Deactivates the community + * @returns {Promise} Returns true if the operation completed successfully, false otherwise + */ + async deactivate() { + return await this.client.deactivateCommunity(this.id._serialized); } }