Skip to content

Commit

Permalink
fix(group): Fixed Add Member if not an administrator (#1964)
Browse files Browse the repository at this point in the history
Co-authored-by: David Ricardo <[email protected]>
  • Loading branch information
DXPRO and David Ricardo authored Jun 6, 2024
1 parent 6e71b0d commit 4afb4d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/group/functions/addParticipants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const messageCodes: {
200: 'OK',
403: "Can't join this group because the number was restricted it.",
409: "Can't join this group because the number is already a member of it.",
421: 'Member not added, awaiting approval!',
};

/**
Expand Down
10 changes: 7 additions & 3 deletions src/group/functions/ensureGroup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright 2021 WPPConnect Team
* Copyright 2024 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 Down Expand Up @@ -29,9 +29,13 @@ export async function ensureGroup(groupId: string | Wid, checkIsAdmin = false) {
);
}

await GroupMetadataStore.find(groupChat.id);
const datagroup = await GroupMetadataStore.find(groupChat.id);

if (checkIsAdmin && !(await iAmAdmin(groupId))) {
if (
checkIsAdmin &&
!(await iAmAdmin(groupId)) &&
datagroup.memberAddMode !== 'all_member_add'
) {
throw new WPPError(
'group_you_are_not_admin',
`You are not admin in ${groupChat.id._serialized}`
Expand Down
3 changes: 2 additions & 1 deletion src/whatsapp/models/GroupMetadataModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright 2021 WPPConnect Team
* Copyright 2024 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 Down Expand Up @@ -28,6 +28,7 @@ interface Props {
id: Wid;
creation?: any;
owner?: any;
memberAddMode?: string;
subject?: string;
subjectTime?: any;
desc?: string;
Expand Down

0 comments on commit 4afb4d4

Please sign in to comment.