fix(worker): reactorJid null guard, document reaction removal, restore comments

This commit is contained in:
2026-05-27 17:03:47 +05:30
parent f255ef91fb
commit 705bd177e8
2 changed files with 27 additions and 1 deletions
@@ -140,4 +140,21 @@ describe('normalizeReaction', () => {
} as proto.IWebMessageInfo; } as proto.IWebMessageInfo;
expect(normalizeReaction(msg, 'acc_1')).toBeNull(); expect(normalizeReaction(msg, 'acc_1')).toBeNull();
}); });
it('returns null when key is missing', () => {
const result = normalizeReaction({ message: { reactionMessage: { key: { id: 'T' }, text: '⭐' } } } as proto.IWebMessageInfo, 'acc_1');
expect(result).toBeNull();
});
it('returns null when participant (reactorJid) is missing', () => {
const msg = {
key: {
remoteJid: '120363043312345678@g.us',
fromMe: false,
id: 'ID',
},
message: { reactionMessage: { key: { id: 'TARGET' }, text: '⭐' } },
} as proto.IWebMessageInfo;
expect(normalizeReaction(msg, 'acc_1')).toBeNull();
});
}); });
+10 -1
View File
@@ -22,7 +22,9 @@ export function normalizeMessage(
if (!key) return null; if (!key) return null;
const remoteJid = key.remoteJid ?? ''; const remoteJid = key.remoteJid ?? '';
// only group messages (group JIDs end with @g.us)
if (!remoteJid.endsWith('@g.us')) return null; if (!remoteJid.endsWith('@g.us')) return null;
// skip our own outgoing messages
if (key.fromMe) return null; if (key.fromMe) return null;
if (!msg.message) return null; if (!msg.message) return null;
@@ -49,7 +51,9 @@ export function normalizeReaction(
if (!key) return null; if (!key) return null;
const remoteJid = key.remoteJid ?? ''; const remoteJid = key.remoteJid ?? '';
// only group messages (group JIDs end with @g.us)
if (!remoteJid.endsWith('@g.us')) return null; if (!remoteJid.endsWith('@g.us')) return null;
// skip our own outgoing messages
if (key.fromMe) return null; if (key.fromMe) return null;
const reaction = msg.message?.reactionMessage; const reaction = msg.message?.reactionMessage;
@@ -58,10 +62,15 @@ export function normalizeReaction(
const targetMsgId = reaction.key?.id; const targetMsgId = reaction.key?.id;
if (!targetMsgId) return null; if (!targetMsgId) return null;
// Ensure reactorJid is not empty (group message must have a participant)
const reactorJid = key.participant;
if (!reactorJid) return null;
return { return {
reactorJid: key.participant ?? '', reactorJid,
targetMsgId, targetMsgId,
sourceGroupJid: remoteJid, sourceGroupJid: remoteJid,
// emoji is empty string ('') when reaction was removed (retraction)
emoji: reaction.text ?? '', emoji: reaction.text ?? '',
accountId, accountId,
}; };