fix(worker): reactorJid null guard, document reaction removal, restore comments
This commit is contained in:
@@ -140,4 +140,21 @@ describe('normalizeReaction', () => {
|
||||
} as proto.IWebMessageInfo;
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,9 @@ export function normalizeMessage(
|
||||
if (!key) return null;
|
||||
|
||||
const remoteJid = key.remoteJid ?? '';
|
||||
// only group messages (group JIDs end with @g.us)
|
||||
if (!remoteJid.endsWith('@g.us')) return null;
|
||||
// skip our own outgoing messages
|
||||
if (key.fromMe) return null;
|
||||
if (!msg.message) return null;
|
||||
|
||||
@@ -49,7 +51,9 @@ export function normalizeReaction(
|
||||
if (!key) return null;
|
||||
|
||||
const remoteJid = key.remoteJid ?? '';
|
||||
// only group messages (group JIDs end with @g.us)
|
||||
if (!remoteJid.endsWith('@g.us')) return null;
|
||||
// skip our own outgoing messages
|
||||
if (key.fromMe) return null;
|
||||
|
||||
const reaction = msg.message?.reactionMessage;
|
||||
@@ -58,10 +62,15 @@ export function normalizeReaction(
|
||||
const targetMsgId = reaction.key?.id;
|
||||
if (!targetMsgId) return null;
|
||||
|
||||
// Ensure reactorJid is not empty (group message must have a participant)
|
||||
const reactorJid = key.participant;
|
||||
if (!reactorJid) return null;
|
||||
|
||||
return {
|
||||
reactorJid: key.participant ?? '',
|
||||
reactorJid,
|
||||
targetMsgId,
|
||||
sourceGroupJid: remoteJid,
|
||||
// emoji is empty string ('') when reaction was removed (retraction)
|
||||
emoji: reaction.text ?? '',
|
||||
accountId,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user