Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(baileys): clear a turned-off timer on the twin chat record
Yudhi Armyndharis03070121812e
diff --git a/src/engine/adapters/baileys-session-store.spec.ts b/src/engine/adapters/baileys-session-store.spec.tsindex 5ac26f525..38bd9aab2 100644--- a/src/engine/adapters/baileys-session-store.spec.ts+++ b/src/engine/adapters/baileys-session-store.spec.ts@@ -581,6 +581,18 @@ describe('BaileysSessionStore', () => {expect(store.getEphemeralExpiration('[email protected]')).toBeUndefined();});+ it.each([+ ['111@lid', '[email protected]'],+ ['[email protected]', '111@lid'],+ ])('clears a timer stored on the %s chat when the %s twin turns it off', (stored, updated) => {+ store.addLidMappings([{ lid: '111@lid', pn: '[email protected]' }]);+ store.upsertChats([{ id: stored, ephemeralExpiration: 86400 }]);+ store.upsertChats([{ id: updated, ephemeralExpiration: null }]);+ expect(store.getEphemeralExpiration('111@lid')).toBeUndefined();+ expect(store.getEphemeralExpiration('[email protected]')).toBeUndefined();+ expect(store.getEphemeralExpiration('[email protected]')).toBeUndefined();+ });+it('keeps a message-learned timer when a chat update does not carry ephemeralExpiration', () => {store.recordMessage({key: { remoteJid: '[email protected]', fromMe: false, id: 'M1' },diff --git a/src/engine/adapters/baileys-session-store.ts b/src/engine/adapters/baileys-session-store.tsindex a14360176..e2b152c2c 100644--- a/src/engine/adapters/baileys-session-store.ts+++ b/src/engine/adapters/baileys-session-store.ts@@ -305,7 +305,8 @@ export class BaileysSessionStore {// A timer the chat itself reports (Baileys emits the EPHEMERAL_SETTING change as chats.update) is// newer than the one learned from messages, and turning the timer off produces no stamped message// that could clear it. Own key only, as in persistChatState: history-sync proto defaults are not news.- // Every twin: own sends cache the timer under the phone spelling of a chat Baileys keys by its lid.+ // Every twin: own sends cache the timer under the phone spelling of a chat Baileys keys by its lid,+ // and a twin chat record would otherwise serve the old timer from the getEphemeralExpiration fallback.if (Object.hasOwn(r, 'ephemeralExpiration')) {const exp = r.ephemeralExpiration;for (const key of new Set(this.chatTwins(r.id).flatMap(k => [k, this.toNeutralJid(k)]))) {@@ -314,6 +315,8 @@ export class BaileysSessionStore {} else {this.ephemeralByChat.delete(key);}+ const twin = key === r.id ? undefined : this.chats.get(key);+ if (twin) this.chats.set(key, { ...twin, ephemeralExpiration: exp });}}}