Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(session): leave an edit that repeats the text unmarked
Yudhi Armyndharis24b96278b1e5
diff --git a/src/modules/session/message-edited-marker.spec.ts b/src/modules/session/message-edited-marker.spec.tsindex 145b773c9..6143ad1c3 100644--- a/src/modules/session/message-edited-marker.spec.ts+++ b/src/modules/session/message-edited-marker.spec.ts@@ -94,6 +94,27 @@ describe('persisted edited message marker', () => {expect(stored.metadata).toEqual({ ...metadata, edited: true });});+ // A body event that repeats the stored text is no edit; it is still announced, as it always was.+ it('does not mark an edit that leaves the stored text as it is', async () => {+ await seed();+ projector.applyMessageEditQueued('s1', { ...edit, body: 'old' });+ await drain();+ const stored = await repository.findOneByOrFail({ waMessageId: edit.messageId });+ expect(stored.body).toBe('old');+ expect(stored.metadata).toEqual(metadata);+ expect(emit).toHaveBeenCalledTimes(1);+ });++ it('marks an edit of a row stored without a text', async () => {+ await seed();+ await repository.update({ waMessageId: edit.messageId }, { body: () => 'NULL' });+ projector.applyMessageEditQueued('s1', edit);+ await drain();+ const stored = await repository.findOneByOrFail({ waMessageId: edit.messageId });+ expect(stored.body).toBe('new');+ expect(stored.metadata).toEqual({ ...metadata, edited: true });+ });+it('does not restore or mark a revoked message', async () => {await seed('revoked');await repository.update({ waMessageId: edit.messageId }, { body: '', metadata: {} });diff --git a/src/modules/session/message-mutation-projector.ts b/src/modules/session/message-mutation-projector.tsindex e609fe13f..9da708a6a 100644--- a/src/modules/session/message-mutation-projector.ts+++ b/src/modules/session/message-mutation-projector.ts@@ -59,20 +59,23 @@ export class MessageMutationProjector {/*** What the stored row says of a change: whether there is one to ask, and why the change must not touch- * it (null when it may). A row that cannot be read is reported absent with no reason, as before.+ * it (null when it may), with the text it holds. A row that cannot be read is reported absent with no+ * reason, as before.*/async storedRowVerdict(sessionId: string,waMessageId: string,source: MutationSource,- ): Promise<{ exists: boolean; reason: string | null }> {+ ): Promise<{ exists: boolean; reason: string | null; body?: string }> {if (!waMessageId) return { exists: false, reason: null };try {const row = await this.messageRepository.findOne({where: { sessionId, waMessageId },- select: { chatId: true, direction: true, author: true },+ select: { chatId: true, direction: true, author: true, body: true },});- return row ? { exists: true, reason: mutationTargetsForeignRow(row, source) } : { exists: false, reason: null };+ return row+ ? { exists: true, reason: mutationTargetsForeignRow(row, source), body: row.body }+ : { exists: false, reason: null };} catch {return { exists: false, reason: null };}@@ -151,7 +154,8 @@ export class MessageMutationProjector {{ sessionId: id, waMessageId: message.messageId, type: Not('revoked') },{ body: message.body },);- await this.markMessageEdited(id, message.messageId);+ // An event that repeats the stored text is no edit, and the marker would label an unedited message.+ if (verdict.body !== message.body) await this.markMessageEdited(id, message.messageId);} catch (err) {this.logger.error(`Failed to update edited message: ${message.messageId}`, String(err));}