From 2fe00d55d95cab09771c8f58ecd5c0273495549c Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Mon, 11 Mar 2024 11:58:12 +0100 Subject: [PATCH] fix: ignore MLS error and use concurrent map in the sub conversation (#2602) --- .../wire/kalium/logic/CoreCryptoExceptionMapper.kt | 1 + .../kotlin/com/wire/kalium/logic/CoreFailure.kt | 2 +- .../data/conversation/SubconversationRepository.kt | 3 ++- .../com/wire/kalium/logic/data/event/EventMapper.kt | 12 ++++++------ .../conversation/message/MLSMessageFailureHandler.kt | 1 + 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt index 8a3474f061c..c67d4c181f0 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/CoreCryptoExceptionMapper.kt @@ -31,6 +31,7 @@ actual fun mapMLSException(exception: Exception): MLSFailure = is CryptoError.StaleProposal -> MLSFailure.StaleProposal is CryptoError.StaleCommit -> MLSFailure.StaleCommit is CryptoError.ConversationAlreadyExists -> MLSFailure.ConversationAlreadyExists + is CryptoError.MessageEpochTooOld -> MLSFailure.MessageEpochTooOld else -> MLSFailure.Generic(exception) } } else { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt index 1a62c65844e..b1fe4ab2809 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt @@ -191,7 +191,7 @@ interface MLSFailure : CoreFailure { data object UnmergedPendingGroup : MLSFailure data object ConversationAlreadyExists : MLSFailure - + data object MessageEpochTooOld : MLSFailure data object ConversationDoesNotSupportMLS : MLSFailure data object StaleProposal : MLSFailure data object StaleCommit : MLSFailure diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/SubconversationRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/SubconversationRepository.kt index a07a28b221e..f2a1a6e8a9b 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/SubconversationRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/SubconversationRepository.kt @@ -20,6 +20,7 @@ package com.wire.kalium.logic.data.conversation import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.id.GroupID import com.wire.kalium.logic.data.id.SubconversationId +import io.ktor.util.collections.ConcurrentMap import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -35,7 +36,7 @@ interface SubconversationRepository { class SubconversationRepositoryImpl : SubconversationRepository { private val mutex = Mutex() - private val subconversations = mutableMapOf, GroupID>() + private val subconversations = ConcurrentMap, GroupID>() override suspend fun insertSubconversation(conversationId: ConversationId, subconversationId: SubconversationId, groupId: GroupID) { mutex.withLock { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt index 33c8af4fdc5..bdabfbf3dde 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt @@ -284,12 +284,12 @@ class EventMapper( id: String, eventContentDTO: EventContentDTO.Conversation.NewMLSMessageDTO, ) = Event.Conversation.NewMLSMessage( - id, - eventContentDTO.qualifiedConversation.toModel(), - eventContentDTO.subconversation?.let { SubconversationId(it) }, - eventContentDTO.qualifiedFrom.toModel(), - eventContentDTO.time, - eventContentDTO.message + id = id, + conversationId = eventContentDTO.qualifiedConversation.toModel(), + subconversationId = eventContentDTO.subconversation?.let { SubconversationId(it) }, + senderUserId = eventContentDTO.qualifiedFrom.toModel(), + timestampIso = eventContentDTO.time, + content = eventContentDTO.message ) private fun connectionUpdate( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt index e0f25104ab7..e9646942f4d 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt @@ -41,6 +41,7 @@ internal object MLSMessageFailureHandler { is MLSFailure.UnmergedPendingGroup -> MLSMessageFailureResolution.Ignore is MLSFailure.StaleProposal -> MLSMessageFailureResolution.Ignore is MLSFailure.StaleCommit -> MLSMessageFailureResolution.Ignore + is MLSFailure.MessageEpochTooOld -> MLSMessageFailureResolution.Ignore else -> MLSMessageFailureResolution.InformUser } }