Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(session): keep a late reaction off a revoked message's row
Yudhi Armyndharis9861677aa058
diff --git a/src/modules/session/message-mutation-projector.ts b/src/modules/session/message-mutation-projector.tsindex aa72a6db2..dd18236f2 100644--- a/src/modules/session/message-mutation-projector.ts+++ b/src/modules/session/message-mutation-projector.ts@@ -53,7 +53,11 @@ export class MessageMutationProjector {// no protection against that — the row it finds is real, just the wrong one.if (!event.messageId) return;- const msg = await this.messageRepository.findOne({ where: { sessionId: id, waMessageId: event.messageId } });+ // A revoked row reads as absent, like the edit paths: a reaction that lands after the delete must+ // not write a reactions map back onto the cleared metadata.+ const msg = await this.messageRepository.findOne({+ where: { sessionId: id, waMessageId: event.messageId, type: Not('revoked') },+ });// The stored copy is best-effort — a message is absent whenever it was never persisted (an// ephemeral one under STORE_EPHEMERAL_MESSAGES=false, or one that arrived before the sessiondiff --git a/src/modules/session/message-projector.service.spec.ts b/src/modules/session/message-projector.service.spec.tsindex 5d5e14487..0ec7f520d 100644--- a/src/modules/session/message-projector.service.spec.ts+++ b/src/modules/session/message-projector.service.spec.ts@@ -785,6 +785,19 @@ describe('MessageProjector (inbound projection)', () => {expect(messageRepository.update.mock.calls.at(-1)).toEqual([where, revokedPatch]);});+ it('takes no reaction that arrives after the revoke, and announces it without a snapshot', async () => {+ const revoked = { ...where, ...revokedPatch };+ messageRepository.findOne.mockImplementation(({ where: w }: { where: { type?: unknown } }) =>+ Promise.resolve(w.type ? null : revoked),+ );++ projector.applyReactionQueued(SESSION_ID, { messageId: 'wamid.1', senderId: '[email protected]', reaction: 'ok' } as never);+ await flush();++ expect(messageRepository.update).not.toHaveBeenCalled();+ expect(dispatchPayload(webhookService.dispatch)).not.toHaveProperty('reactions');+ });+it('never takes an edit, inbound or outbound', async () => {projector.applyMessageEditQueued(SESSION_ID, { messageId: 'wamid.1', body: 'late' } as never);await projector.recordOutboundMessageEdit(SESSION_ID, 'wamid.1', 'later');