Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(session): record the revoke of an arriving message at once
Yudhi Armyndharis486f0a8c27bf
diff --git a/src/modules/session/message-projector.inbound-hold.spec.ts b/src/modules/session/message-projector.inbound-hold.spec.tsindex 63ea6d0a0..d209676ac 100644--- a/src/modules/session/message-projector.inbound-hold.spec.ts+++ b/src/modules/session/message-projector.inbound-hold.spec.ts@@ -194,6 +194,46 @@ describe('MessageProjector holding inbound messages (PostgreSQL)', () => {expect(eventsGateway.emitMessage).not.toHaveBeenCalled();});+ it('stores a message cleared when an actor-bearing revoke reaches it while the row read is still out', async () => {+ const t = admit(arrival('A', 'chat1', true));+ const gate = deferred<void>();+ const read = repo.findOne as jest.Mock;+ const unrestricted = read.getMockImplementation() as (arg: unknown) => Promise<unknown>;+ read.mockImplementation(async (arg: unknown) => {+ await gate.promise;+ return unrestricted(arg);+ });+ projector.handleMessageRevoked(+ 's1',+ engine,+ {+ id: 'A',+ revokedId: 'A',+ chatId: 'chat1',+ from: 'chat1',+ to: '[email protected]',+ type: 'revoked',+ body: '',+ timestamp: 1,+ },+ { fromMe: false },+ );+ projector.handleInboundMessage(+ 's1',+ engine,+ message('A', 'chat1', { type: 'image', body: 'secret', media: { mimetype: 'image/png', data: 'QUJD' } }),+ t,+ );+ await flush();+ gate.resolve();+ await flush();++ expect(hookStarts).toEqual([]);+ expect(rows).toEqual([expect.objectContaining({ waMessageId: 'A', body: '', type: 'revoked', metadata: null })]);+ expect(dispatched('message.received')).toEqual([]);+ expect(eventsGateway.emitMessage).not.toHaveBeenCalled();+ });+it('runs the hook, stores and announces a message edited before its emit with the edit', async () => {const t = admit(arrival('A', 'chat1'));projector.applyMessageEditQueued('s1', { messageId: 'A', body: 'edited' } as never);diff --git a/src/modules/session/message-projector.service.ts b/src/modules/session/message-projector.service.tsindex efff68c32..03c149ebc 100644--- a/src/modules/session/message-projector.service.ts+++ b/src/modules/session/message-projector.service.ts@@ -1154,8 +1154,10 @@ export class MessageProjector {};// An engine that applies no validation to a revoke says who made it, and the stored row says whose// message it names: a revoke the row proves foreign is dropped, announcement included. whatsapp-web.js- // reports only what WhatsApp Web itself accepted, so it passes no actor and is applied at once.- if (!actor) {+ // reports only what WhatsApp Web itself accepted, so it passes no actor and is applied at once. So is+ // the revoke of a message still arriving: it has no row to be checked against, and waiting for a read+ // would let its emit run, and announce the deleted content, first.+ if (!actor || this.inboundInFlight.has(`${id}:${revokedWaMessageId}`)) {apply();return;}