fix: No session found to decrypt message and recover lost messages due to this reason (#1822)

* fix: improve message resend logic by adding checks for message IDs

* Revert "fix: improve message resend logic by adding checks for message IDs"

This reverts commit c03f9d8e6fc6cbfbb9d1f8f67c169700e704213d.

* fix: handle device identity inclusion for retry resends in message sending

* feat: lint fix

---------

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
This commit is contained in:
Matheus Filype
2025-09-26 09:48:04 -03:00
committed by GitHub
parent 7b0e39f443
commit 7d5c28cf72
+26 -8
View File
@@ -569,7 +569,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
) => {
const meId = authState.creds.me!.id
const meLid = authState.creds.me?.lid
let shouldIncludeDeviceIdentity = false
const isRetryResend = Boolean(participant?.jid)
let shouldIncludeDeviceIdentity = isRetryResend
const statusJid = 'status@broadcast'
const { user, server } = jidDecode(jid)!
@@ -722,7 +723,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
for (const device of devices) {
const deviceJid = device.wireJid
const hasKey = !!senderKeyMap[deviceJid]
if (!hasKey || !!participant) {
if (!hasKey && !isRetryResend) {
senderKeyRecipients.push(deviceJid)
senderKeyMap[deviceJid] = true
}
@@ -752,13 +753,30 @@ export const makeMessagesSocket = (config: SocketConfig) => {
participants.push(...result.nodes)
}
binaryNodeContent.push({
tag: 'enc',
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
content: ciphertext
})
if (isRetryResend) {
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
data: bytes,
jid: participant?.jid!
})
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } })
binaryNodeContent.push({
tag: 'enc',
attrs: {
v: '2',
type,
count: participant!.count.toString()
},
content: encryptedContent
})
} else {
binaryNodeContent.push({
tag: 'enc',
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
content: ciphertext
})
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } })
}
} else {
const { user: ownUser } = jidDecode(ownId)!