Skip to content

Commit

Permalink
fix: Fixed group.participant_changed event for WhatsApp >= 2.2234.6 (w…
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Sep 17, 2022
1 parent 49e8311 commit b60a9b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/group/events/registerParticipantsChangedEvent.ts
Expand Up @@ -16,6 +16,7 @@

import { internalEv } from '../../eventEmitter';
import * as webpack from '../../webpack';
import { Wid } from '../../whatsapp';
import { wrapModuleFunction } from '../../whatsapp/exportModule';
import { updateDBForGroupAction } from '../../whatsapp/functions';

Expand All @@ -30,11 +31,18 @@ function register() {
let actionType = action.actionType || action.action;
if (eventTypes.includes(actionType)) {
queueMicrotask(() => {
const participants: Wid[] = action.participants.map((p) => {
if ('id' in p) {
return p.id;
}
return p;
});

if (actionType === 'add' && action.isInvite) {
actionType = 'join';
} else if (
actionType === 'remove' &&
action.participants.some((p) => p.equals(meta.author))
participants.some((p) => p.equals(meta.author))
) {
actionType = 'leave';
}
Expand All @@ -45,7 +53,7 @@ function register() {
groupId: meta.chatId.toString(),
action: actionType as any,
operation: (action.actionType || action.action) as any,
participants: action.participants.map((p) => p.toString()),
participants: participants.map((p) => p.toString()),
});
});
}
Expand Down
14 changes: 13 additions & 1 deletion src/whatsapp/functions/updateDBForGroupAction.ts
Expand Up @@ -17,12 +17,24 @@
import { exportModule } from '../exportModule';
import { Wid } from '../misc';

/**
* GroupActionParticipant for @whatsapp >= 2.2234.6
*/
export interface GroupActionParticipant {
id: Wid;
isAdmin: boolean;
isSuperAdmin: boolean;
}

export interface GroupActionChange {
action: string;
actionType: string; // @whatsapp >= 2.2224.6
isInvite?: boolean;
isLinkedGroupJoin?: boolean;
participants: Wid[];
/**
* GroupActionParticipant for @whatsapp >= 2.2234.6
*/
participants: Wid[] | GroupActionParticipant[];
prevVersion: number;
version: number;
}
Expand Down

0 comments on commit b60a9b6

Please sign in to comment.