diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index bb7307d80ce..0b058168dc2 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -151,7 +151,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { await delay(5000) - if (!await placeholderResendCache.get(messageKey?.id!)) { + if (!(await placeholderResendCache.get(messageKey?.id!))) { logger.debug({ messageKey }, 'message received while resend requested') return 'RESOLVED' } @@ -429,12 +429,12 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { let shouldRecreateSession = false let recreateReason = '' - if (enableAutoSessionRecreation && messageRetryManager) { + if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) { try { // Check if we have a session with this JID const sessionId = signalRepository.jidToSignalProtocolAddress(fromJid) const hasSession = await signalRepository.validateSession(fromJid) - const result = messageRetryManager.shouldRecreateSession(fromJid, retryCount, hasSession.exists) + const result = messageRetryManager.shouldRecreateSession(fromJid, hasSession.exists) shouldRecreateSession = result.recreate recreateReason = result.reason @@ -987,12 +987,12 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { let shouldRecreateSession = false let recreateReason = '' - if (enableAutoSessionRecreation && messageRetryManager) { + if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) { try { const sessionId = signalRepository.jidToSignalProtocolAddress(participant) const hasSession = await signalRepository.validateSession(participant) - const result = messageRetryManager.shouldRecreateSession(participant, retryCount, hasSession.exists) + const result = messageRetryManager.shouldRecreateSession(participant, hasSession.exists) shouldRecreateSession = result.recreate recreateReason = result.reason @@ -1177,7 +1177,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const encNode = getBinaryNodeChild(node, 'enc') // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption - if (encNode && encNode.attrs.type === 'msmsg') { + if (encNode?.attrs.type === 'msmsg') { logger.debug({ key: node.attrs.key }, 'ignored msmsg') await sendMessageAck(node, NACK_REASONS.MissingMessageSecret) return diff --git a/src/Utils/message-retry-manager.ts b/src/Utils/message-retry-manager.ts index 76833dda655..48be547e9ce 100644 --- a/src/Utils/message-retry-manager.ts +++ b/src/Utils/message-retry-manager.ts @@ -109,7 +109,7 @@ export class MessageRetryManager { /** * Check if a session should be recreated based on retry count and history */ - shouldRecreateSession(jid: string, retryCount: number, hasSession: boolean): { reason: string; recreate: boolean } { + shouldRecreateSession(jid: string, hasSession: boolean): { reason: string; recreate: boolean } { // If we don't have a session, always recreate if (!hasSession) { this.sessionRecreateHistory.set(jid, Date.now()) @@ -120,11 +120,6 @@ export class MessageRetryManager { } } - // Only consider recreation if retry count > 1 - if (retryCount < 2) { - return { reason: '', recreate: false } - } - const now = Date.now() const prevTime = this.sessionRecreateHistory.get(jid)