diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 7420ad9b..e2a90d2f 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -587,7 +587,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const willSendMessageAgain = (id: string, participant: string) => { const key = `${id}:${participant}` const retryCount = msgRetryCache.get(key) || 0 - return retryCount < maxMsgRetryCount + return retryCount <= maxMsgRetryCount } const updateSendMessageAgainCount = (id: string, participant: string) => { @@ -614,8 +614,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { logger.debug({ participant, sendToAll }, 'forced new session for retry recp') for (const [i, msg] of msgs.entries()) { - if (msg) { - updateSendMessageAgainCount(ids[i]!, participant) + if (!ids[i]) continue + + if (msg && willSendMessageAgain(ids[i], participant)) { + updateSendMessageAgainCount(ids[i], participant) const msgRelayOpts: MessageRelayOptions = { messageId: ids[i] } if (sendToAll) { @@ -703,9 +705,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { // correctly set who is asking for the retry key.participant = key.participant || attrs.from const retryNode = getBinaryNodeChild(node, 'retry') - if (willSendMessageAgain(ids[0]!, key.participant!)) { + if (ids[0] && key.participant && willSendMessageAgain(ids[0], key.participant!)) { if (key.fromMe) { try { + updateSendMessageAgainCount(ids[0], key.participant) logger.debug({ attrs, key }, 'recv retry request') await sendMessagesAgain(key, ids, retryNode!) } catch (error: any) {