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:
@@ -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)!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user