diff --git a/lib/tunnelbroker/use-peer-to-peer-message-handler.js b/lib/tunnelbroker/use-peer-to-peer-message-handler.js --- a/lib/tunnelbroker/use-peer-to-peer-message-handler.js +++ b/lib/tunnelbroker/use-peer-to-peer-message-handler.js @@ -323,6 +323,21 @@ ); return; } + + if (errorMessage.includes(olmSessionErrors.alreadyDecrypted)) { + const sqliteMessages = await sqliteAPI.getInboundP2PMessagesByID([ + messageID, + ]); + if (sqliteMessages.length > 0) { + console.log( + 'Message skipped because it was already decrypted ' + + `messageId: ${messageID}` + + `sender: ${message.senderInfo.deviceID}.`, + ); + return; + } + } + console.log( 'Error decrypting message from device ' + `${message.senderInfo.deviceID}: ${errorMessage}`, diff --git a/lib/utils/olm-utils.js b/lib/utils/olm-utils.js --- a/lib/utils/olm-utils.js +++ b/lib/utils/olm-utils.js @@ -128,6 +128,7 @@ // the corresponding .cpp file // at `native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp`. invalidSessionVersion: 'INVALID_SESSION_VERSION', + alreadyDecrypted: `${OLM_SESSION_ERROR_PREFIX}ALREADY_DECRYPTED_OR_KEYS_SKIPPED`, }); function hasHigherDeviceID(