Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(baileys): apply a message edit or delete to every chat twin
Yudhi Armyndharis35dcbc1a03cf
diff --git a/src/engine/adapters/baileys-session-store.spec.ts b/src/engine/adapters/baileys-session-store.spec.tsindex c65577d48..adcd53aa7 100644--- a/src/engine/adapters/baileys-session-store.spec.ts+++ b/src/engine/adapters/baileys-session-store.spec.ts@@ -441,6 +441,21 @@ describe('BaileysSessionStore', () => {expect(store.listChats()[0]).toEqual(expect.objectContaining({ lastMessage: 'after edit', timestamp: 200 }));});+ it.each([+ ['its own id, once only the phone twin has a chat record', ['[email protected]'], '999@lid'],+ ['the phone twin, when both twins have a chat record', ['[email protected]', '999@lid'], '[email protected]'],+ ])('updates a lid-filed preview when the edit arrives through %s', (_label, chats, editedVia) => {+ store.addLidMappings([{ lid: '999@lid', pn: '[email protected]' }]);+ store.recordMessage({+ key: { remoteJid: '999@lid', id: 'M1' },+ message: { conversation: 'secret' },+ messageTimestamp: 200,+ });+ store.upsertChats(chats.map(id => ({ id })));+ store.recordMessageEdit(editedVia, 'M1', '');+ expect(store.listChats().map(c => c.lastMessage)).toEqual(['']);+ });+it('flags a group chat by jid', () => {store.upsertChats([{ id: '[email protected]', name: 'Grp' }]);expect(store.listChats()[0].isGroup).toBe(true);diff --git a/src/engine/adapters/baileys-session-store.ts b/src/engine/adapters/baileys-session-store.tsindex 70188d6f1..1c43bd6fa 100644--- a/src/engine/adapters/baileys-session-store.ts+++ b/src/engine/adapters/baileys-session-store.ts@@ -426,14 +426,15 @@ export class BaileysSessionStore {/*** Refresh the chat preview when (and only when) the edited message is still the latest message in- * that chat. Editing an older message must not replace the preview or reorder the conversation.+ * that chat. Editing an older message must not replace the preview or reorder the conversation. The+ * preview may sit on any twin of the chat, the one the listing reads included, so each is checked.*/recordMessageEdit(chatId: string, messageId: string, text: string): void {if (!messageId) return;- const key = this.chatKey(chatId);- const existing = this.lastMessages.get(key);- if (!existing || existing.key.id !== messageId) return;- this.lastMessages.set(key, { ...existing, text });+ for (const key of new Set([this.chatKey(chatId), ...this.chatTwins(chatId)])) {+ const existing = this.lastMessages.get(key);+ if (existing?.key.id === messageId) this.lastMessages.set(key, { ...existing, text });+ }}/**