From f2c4e466efc48c907b688afb08937f4e8e094241 Mon Sep 17 00:00:00 2001 From: Renato Alcara Date: Wed, 25 Feb 2026 21:56:36 -0300 Subject: [PATCH] fix(retry): resolve message-not-found for device-specific JID retry receipts fix(retry): resolve message-not-found for device-specific JID retry receipts --- src/Utils/message-retry-manager.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Utils/message-retry-manager.ts b/src/Utils/message-retry-manager.ts index 4a0336ad..59164f07 100644 --- a/src/Utils/message-retry-manager.ts +++ b/src/Utils/message-retry-manager.ts @@ -156,12 +156,28 @@ export class MessageRetryManager { } /** - * Get a recent message from the cache + * Get a recent message from the cache. + * + * First attempts an exact `to+id` key lookup. If that misses — which happens when + * the retry receipt arrives from a device-specific JID (e.g. `55123:82@s.whatsapp.net`) + * while the message was stored under the normalised base JID (`55123@s.whatsapp.net`), + * or when the JID domain flipped between LID and PN — falls back to the `messageKeyIndex` + * which maps bare message IDs to stored keys regardless of the `to` format. */ getRecentMessage(to: string, id: string): RecentMessage | undefined { const key: RecentMessageKey = { to, id } const keyStr = this.keyToString(key) - return this.recentMessagesMap.get(keyStr) + const exact = this.recentMessagesMap.get(keyStr) + if (exact) return exact + + // Fallback: look up by message ID only to handle JID format mismatches + // (device suffix present/absent, LID vs PN, etc.) + const indexedKeyStr = this.messageKeyIndex.get(id) + if (indexedKeyStr) { + return this.recentMessagesMap.get(indexedKeyStr) + } + + return undefined } /**