Skip to content

Commit

Permalink
added deactivateCommunity method
Browse files Browse the repository at this point in the history
  • Loading branch information
alechkos committed Sep 29, 2023
1 parent 4ddd78d commit 2bef97e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ declare namespace WAWebJS {
*/
createCommunity(name: string, description: string, options: CreateCommunityOptions): Promise<CreateCommunityResult>

/** Deactivates the community */
deactivateCommunity: (parentGroupId: string) => Promise<boolean>;

/** Closes the client */
destroy(): Promise<void>

Expand Down Expand Up @@ -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<boolean>;

/** Deactivates the community */
deactivate: () => Promise<boolean>;
}

/** Create community options */
Expand Down
18 changes: 18 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>} 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<Array<Label>>}
Expand Down
19 changes: 10 additions & 9 deletions src/structures/Community.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,10 +99,15 @@ class Community extends GroupChat {
* @returns {Promise<boolean>} 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<boolean>} Returns true if the operation completed successfully, false otherwise
*/
async deactivate() {
return await this.client.deactivateCommunity(this.id._serialized);
}
}

Expand Down

0 comments on commit 2bef97e

Please sign in to comment.