Skip to content

Commit

Permalink
fix: Typos fix for community
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta authored and edgardmessias committed Jan 28, 2023
1 parent d52137b commit 1486b10
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 38 deletions.
46 changes: 46 additions & 0 deletions src/community/functions/addSubgroups.ts
@@ -0,0 +1,46 @@
/*!
* Copyright 2023 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { assertWid } from '../../assert';
import { Wid } from '../../whatsapp';
import { sendLinkSubgroups as SendLinkSubgroups } from '../../whatsapp/functions';

/**
* Add groups do community
*
* @example
* ```javascript
* await WPP.community.addSubgroups('<>@g.us', ['<>@g.us', '<>@g.us']);
* ```
*/

export async function addSubgroups(
parentGroupId: string | Wid,
subgroupIds: (string | Wid) | (string | Wid)[]
): Promise<{
failedGroups: { error: string; jid: string }[];
linkedGroupJids: string[];
}> {
if (!Array.isArray(subgroupIds)) {
subgroupIds = [subgroupIds];
}
const parentWid = assertWid(parentGroupId);
const subGroupsWids = subgroupIds.map(assertWid);
return await SendLinkSubgroups({
parentGroupId: parentWid,
subgroupIds: subGroupsWids,
});
}
31 changes: 23 additions & 8 deletions src/community/functions/create.ts
@@ -1,5 +1,5 @@
/*!
* Copyright 2021 WPPConnect Team
* Copyright 2023 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,15 @@
* limitations under the License.
*/

import { assertWid } from '../../assert';
import { Wid } from '../../whatsapp';
import { sendCreateCommunity } from '../../whatsapp/functions';
import { sendLinkSubgroups } from './sendLinkSubgroups';
import {
sendCreateCommunity,
sendLinkSubgroups,
} from '../../whatsapp/functions';

/**
* Create community
* Create a community
*
* @example
* ```javascript
Expand All @@ -29,13 +32,25 @@ import { sendLinkSubgroups } from './sendLinkSubgroups';
export async function create(
name: string,
desc: string,
subGroupsIds: Wid[]
subGroupsIds: (string | Wid) | (string | Wid)[]
): Promise<any> {
const community = await sendCreateCommunity({
if (!Array.isArray(subGroupsIds)) {
subGroupsIds = [subGroupsIds];
}

const subGroupsWids = subGroupsIds.map(assertWid);
const result = await sendCreateCommunity({
name: name,
desc: desc,
closed: false,
});
console.log(community);
return await sendLinkSubgroups(community.wid, subGroupsIds);
await sendLinkSubgroups({
parentGroupId: result.wid,
subgroupIds: subGroupsWids,
});

return {
wid: result.wid,
subGroups: subGroupsWids,
};
}
Expand Up @@ -14,24 +14,22 @@
* limitations under the License.
*/

import { assertWid } from '../../assert';
import { Wid } from '../../whatsapp';
import { sendLinkSubgroups as SendLinkSubgroups } from '../../whatsapp/functions';
import { sendDeactivateCommunity as SendDeactivateCommunity } from '../../whatsapp/functions';

/**
* Add groups do tommunity
* Deactivated a community
*
* @example
* ```javascript
* await WPP.community.sendLinkSubgroups('<>@g.us', ['<>@g.us', '<>@g.us']);
* await WPP.community.deactivate('<>@g.us');
* ```
*/

export async function sendLinkSubgroups(
parentGroupId: Wid,
subgroupIds: Wid | Wid[]
): Promise<any> {
return SendLinkSubgroups({
parentGroupId: parentGroupId,
subgroupIds: subgroupIds,
export async function deactivate(communityId: string | Wid): Promise<any> {
const wid = assertWid(communityId);
return SendDeactivateCommunity({
parentGroupId: wid,
});
}
Expand Up @@ -14,18 +14,20 @@
* limitations under the License.
*/

import { assertWid } from '../../assert';
import { Wid } from '../../whatsapp';
import { getCommunityParticipants as GetCommunityParticipants } from '../../whatsapp/functions';

/**
* Add groups do tommunity
* Get all participants of a community
*
* @example
* ```javascript
* await WPP.community.getCommunityParticipants('<>@g.us');
* await WPP.community.getParticipants('<>@g.us');
* ```
*/

export async function getCommunityParticipants(communityId: Wid): Promise<any> {
return GetCommunityParticipants(communityId);
export async function getParticipants(communityId: string | Wid): Promise<any> {
const wid = assertWid(communityId);
return GetCommunityParticipants(wid);
}
7 changes: 4 additions & 3 deletions src/community/functions/index.ts
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

export { addSubgroups } from './addSubgroups';
export { create } from './create';
export { getCommunityParticipants } from './getCommunityParticipants';
export { sendLinkSubgroups } from './sendLinkSubgroups';
export { sendUnlinkSubgroups } from './sendUnlinkSubgroups';
export { deactivate } from './deactivate';
export { getParticipants } from './getParticipants';
export { removeSubgroups } from './removeSubgroups';
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { assertWid } from '../../assert';
import { Wid } from '../../whatsapp';
import { sendUnlinkSubgroups as SendUnlinkSubgroups } from '../../whatsapp/functions';

Expand All @@ -26,12 +27,20 @@ import { sendUnlinkSubgroups as SendUnlinkSubgroups } from '../../whatsapp/funct
* ```
*/

export async function sendUnlinkSubgroups(
parentGroupId: Wid,
subgroupIds: Wid | Wid[]
): Promise<any> {
return SendUnlinkSubgroups({
parentGroupId: parentGroupId,
subgroupIds: subgroupIds,
export async function removeSubgroups(
parentGroupId: string | Wid,
subgroupIds: (string | Wid) | (string | Wid)[]
): Promise<{
failedGroups: { error: string; jid: string }[];
linkedGroupJids: string[];
}> {
if (!Array.isArray(subgroupIds)) {
subgroupIds = [subgroupIds];
}
const parentWid = assertWid(parentGroupId);
const subGroupsWids = subgroupIds.map(assertWid);
return await SendUnlinkSubgroups({
parentGroupId: parentWid,
subgroupIds: subGroupsWids,
});
}
7 changes: 1 addition & 6 deletions src/whatsapp/functions/sendCreateCommunity.ts
Expand Up @@ -63,10 +63,5 @@ exportModule(
sendRemoveFromCommunityCommunity: 'sendRemoveFromCommunityCommunity',
sendUnlinkSubgroups: 'sendUnlinkSubgroups',
},
(m) =>
m.sendCreateCommunity &&
m.sendDeactivateCommunity &&
m.sendLinkSubgroups &&
m.sendRemoveFromCommunityCommunity &&
m.sendUnlinkSubgroups
(m) => m.sendCreateCommunity
);

0 comments on commit 1486b10

Please sign in to comment.