Skip to content

Commit

Permalink
fix: Improovment on remove participant group (close wppconnect-team#1814
Browse files Browse the repository at this point in the history
)
  • Loading branch information
icleitoncosta authored and qeternity committed May 12, 2024
1 parent 5b8670a commit 4c461f5
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/group/functions/removeParticipants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
* limitations under the License.
*/

import { assertWid } from '../../assert';
import { WPPError } from '../../util';
import { Wid } from '../../whatsapp';
import { ParticipantModel, Wid } from '../../whatsapp';
import * as wa_functions from '../../whatsapp/functions';
import { ensureGroup } from './ensureGroup';
import { ensureGroupAndParticipants } from './ensureGroupAndParticipants';

/**
Expand All @@ -37,11 +39,24 @@ export async function removeParticipants(
groupId: string | Wid,
participantsIds: (string | Wid) | (string | Wid)[]
): Promise<void> {
const { groupChat, participants } = await ensureGroupAndParticipants(
groupId,
participantsIds
);
if (!Array.isArray(participantsIds)) {
participantsIds = [participantsIds];
}
const groupChat = await ensureGroup(groupId, true);
const validWids: Wid[] = [];
const wids = participantsIds.map(assertWid);

wids.map<ParticipantModel | any>((wid) => {
const participant = groupChat.groupMetadata?.participants.get(wid);
if (participant) validWids.push(wid);
});
if (validWids.length === 0)
throw new WPPError(
'not_valid_group_participants',
`No valid participants found for the group ${groupId}`
);

const { participants } = await ensureGroupAndParticipants(groupId, validWids);
if (
participants.some(
(p) => !groupChat.groupMetadata?.participants.canRemove(p)
Expand Down

0 comments on commit 4c461f5

Please sign in to comment.