Skip to content

Commit 6e21157

Browse files
Alexey Poliakovclaude
andcommitted
fix(revoke): use protocolMessageKey for original message ID
Cherry-picked from wwebjs#201696: - Use msg.protocolMessageKey directly to identify revoked message - Filter change:type event to only fire on revoked type - Removes last_message tracking heuristic PR 201698 (getContacts) skipped: our existing implementation already properly resolves promises and attaches businessProfile. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3d44600 commit 6e21157

1 file changed

Lines changed: 18 additions & 28 deletions

File tree

src/Client.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -752,46 +752,35 @@ class Client extends EventEmitter {
752752
},
753753
);
754754

755-
let last_message;
756-
757755
await exposeFunctionIfAbsent(
758756
this.pupPage,
759757
'onChangeMessageTypeEvent',
760758
(msg) => {
761-
if (msg.type === 'revoked') {
762-
const message = new Message(this, msg);
763-
let revoked_msg;
764-
if (last_message && msg.id.id === last_message.id.id) {
765-
revoked_msg = new Message(this, last_message);
766-
767-
if (message.protocolMessageKey)
768-
revoked_msg.id = { ...message.protocolMessageKey };
769-
}
759+
const originalKey = msg.protocolMessageKey;
760+
const message = new Message(this, { ...msg, id: originalKey });
761+
const revoked_msg = originalKey
762+
? new Message(this, { id: originalKey })
763+
: undefined;
770764

771-
/**
772-
* Emitted when a message is deleted for everyone in the chat.
773-
* @event Client#message_revoke_everyone
774-
* @param {Message} message The message that was revoked, in its current state. It will not contain the original message's data.
775-
* @param {?Message} revoked_msg The message that was revoked, before it was revoked. It will contain the message's original data.
776-
* Note that due to the way this data is captured, it may be possible that this param will be undefined.
777-
*/
778-
this.emit(
779-
Events.MESSAGE_REVOKED_EVERYONE,
780-
message,
781-
revoked_msg,
782-
);
783-
}
765+
/**
766+
* Emitted when a message is deleted for everyone in the chat.
767+
* @event Client#message_revoke_everyone
768+
* @param {Message} message The message that was revoked, in its current state. It will not contain the original message's data.
769+
* @param {?Message} revoked_msg The message that was revoked, before it was revoked. It will contain the message's original data.
770+
* Note that due to the way this data is captured, it may be possible that this param will be undefined.
771+
*/
772+
this.emit(
773+
Events.MESSAGE_REVOKED_EVERYONE,
774+
message,
775+
revoked_msg,
776+
);
784777
},
785778
);
786779

787780
await exposeFunctionIfAbsent(
788781
this.pupPage,
789782
'onChangeMessageEvent',
790783
(msg) => {
791-
if (msg.type !== 'revoked') {
792-
last_message = msg;
793-
}
794-
795784
/**
796785
* The event notification that is received when one of
797786
* the group participants changes their phone number.
@@ -1120,6 +1109,7 @@ class Client extends EventEmitter {
11201109
window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg));
11211110
});
11221111
Msg.on('change:type', (msg) => {
1112+
if (msg.type !== 'revoked') return;
11231113
window.onChangeMessageTypeEvent(
11241114
window.WWebJS.getMessageModel(msg),
11251115
);

0 commit comments

Comments
 (0)