diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt index d9387ad3..7c5131fc 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt @@ -79,8 +79,7 @@ internal class MXOlmDevice @Inject constructor( // // The first level keys are timeline ids. // The second level keys are strings of form "||" - // Values are true. - private val inboundGroupSessionMessageIndexes: MutableMap> = HashMap() + private val inboundGroupSessionMessageIndexes: MutableMap> = HashMap() init { // Retrieve the account from the store @@ -662,19 +661,17 @@ internal class MXOlmDevice @Inject constructor( } if (null != timeline) { - if (!inboundGroupSessionMessageIndexes.containsKey(timeline)) { - inboundGroupSessionMessageIndexes[timeline] = HashMap() - } + val timelineSet = inboundGroupSessionMessageIndexes.getOrPut(timeline) { mutableSetOf() } val messageIndexKey = senderKey + "|" + sessionId + "|" + decryptResult.mIndex - if (inboundGroupSessionMessageIndexes[timeline]?.get(messageIndexKey) != null) { + if (timelineSet.contains(messageIndexKey)) { val reason = String.format(MXCryptoError.DUPLICATE_MESSAGE_INDEX_REASON, decryptResult.mIndex) Timber.e("## decryptGroupMessage() : $reason") throw MXCryptoError.Base(MXCryptoError.ErrorType.DUPLICATED_MESSAGE_INDEX, reason) } - inboundGroupSessionMessageIndexes[timeline]!!.put(messageIndexKey, true) + timelineSet.add(messageIndexKey) } store.storeInboundGroupSessions(listOf(session))