From 2927269bd035154451b9f7067f0d580f1dd5b418 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 18:20:32 +0200 Subject: [PATCH] =?UTF-8?q?fix(mls-migration):=20set=20correct=20CS=20when?= =?UTF-8?q?=20Kalium=20start=20migration=20(WPB-9638)=20=F0=9F=8D=92=20(#2?= =?UTF-8?q?838)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Commit with unresolved merge conflicts * resolve conflicts --------- Co-authored-by: Mojtaba Chenani --- .../conversation/MLSConversationRepository.kt | 2 ++ .../logic/feature/mlsmigration/MLSMigrator.kt | 18 +++++++----------- .../feature/mlsmigration/MLSMigratorTest.kt | 12 ++++++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt index 417d80d4e68..eeeed7a2283 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt @@ -472,6 +472,7 @@ internal class MLSConversationDataSource( allowPartialMemberList: Boolean = false, ): Either = withContext(serialDispatcher) { commitPendingProposals(groupID).flatMap { + kaliumLogger.d("adding $userIdList to MLS group: $groupID") produceAndSendCommitWithRetryAndResult(groupID, retryOnStaleMessage = retryOnStaleMessage) { keyPackageRepository.claimKeyPackages(userIdList, cipherSuite).flatMap { result -> if (result.usersWithoutKeyPackagesAvailable.isNotEmpty() && !allowPartialMemberList) { @@ -598,6 +599,7 @@ internal class MLSConversationDataSource( externalSenders: ByteArray, allowPartialMemberList: Boolean = false, ): Either = withContext(serialDispatcher) { + kaliumLogger.d("establish MLS group: $groupID") mlsClientProvider.getMLSClient().flatMap { mlsClient -> wrapMLSRequest { mlsClient.createConversation( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrator.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrator.kt index 0577055b6b3..228e7c5ec5e 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrator.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigrator.kt @@ -25,15 +25,16 @@ import com.wire.kalium.logic.data.conversation.Conversation.Protocol import com.wire.kalium.logic.data.conversation.ConversationRepository import com.wire.kalium.logic.data.conversation.MLSConversationRepository import com.wire.kalium.logic.data.id.ConversationId +import com.wire.kalium.logic.data.id.SelfTeamIdProvider import com.wire.kalium.logic.data.message.SystemMessageInserter import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.data.user.UserRepository -import com.wire.kalium.logic.data.id.SelfTeamIdProvider import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.flatMapLeft import com.wire.kalium.logic.functional.fold import com.wire.kalium.logic.functional.foldToEitherWhileRight +import com.wire.kalium.logic.functional.right import com.wire.kalium.logic.kaliumLogger import kotlinx.coroutines.flow.first @@ -107,6 +108,7 @@ internal class MLSMigratorImpl( ) } } + kaliumLogger.i("migrating ${conversationId.toLogString()} to mls") establishConversation(conversationId) }.flatMapLeft { kaliumLogger.w("failed to migrate ${conversationId.toLogString()} to mixed: $it") @@ -135,16 +137,10 @@ internal class MLSMigratorImpl( .flatMap { protocolInfo -> when (protocolInfo) { is Conversation.ProtocolInfo.Mixed -> { - mlsConversationRepository.establishMLSGroup(protocolInfo.groupId, emptyList()) - .flatMap { - conversationRepository.getConversationMembers(conversationId).flatMap { members -> - mlsConversationRepository.addMemberToMLSGroup( - protocolInfo.groupId, - members, - protocolInfo.cipherSuite - ) - } - } + conversationRepository.getConversationMembers(conversationId).flatMap { members -> + mlsConversationRepository.establishMLSGroup(protocolInfo.groupId, members) + } + Unit.right() } else -> Either.Right(Unit) } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigratorTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigratorTest.kt index 8dcd95904ec..d487cade8c5 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigratorTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/mlsmigration/MLSMigratorTest.kt @@ -19,6 +19,7 @@ package com.wire.kalium.logic.feature.mlsmigration import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.NetworkFailure +import com.wire.kalium.logic.StorageFailure import com.wire.kalium.logic.data.call.CallRepository import com.wire.kalium.logic.data.conversation.Conversation import com.wire.kalium.logic.data.conversation.ConversationRepository @@ -35,6 +36,8 @@ import com.wire.kalium.logic.framework.TestConversation import com.wire.kalium.logic.framework.TestTeam import com.wire.kalium.logic.framework.TestUser import com.wire.kalium.logic.functional.Either +import com.wire.kalium.logic.functional.left +import com.wire.kalium.logic.functional.right import com.wire.kalium.logic.test_util.TestNetworkResponseError import com.wire.kalium.logic.util.arrangement.CallRepositoryArrangementImpl import com.wire.kalium.logic.util.shouldSucceed @@ -67,7 +70,7 @@ class MLSMigratorTest { .withFetchConversationSucceeding() .withGetConversationProtocolInfoReturning(Arrangement.MIXED_PROTOCOL_INFO) .withEstablishGroupSucceeds(Arrangement.SUCCESSFUL_ADDITION_RESULT) - .withGetConversationMembersReturning(Arrangement.MEMBERS) + .withGetConversationMembersReturning(Arrangement.MEMBERS.right()) .withAddMembersSucceeds() .withoutAnyEstablishedCall() .arrange() @@ -104,7 +107,7 @@ class MLSMigratorTest { .withFetchConversationSucceeding() .withGetConversationProtocolInfoReturning(Arrangement.MIXED_PROTOCOL_INFO) .withEstablishGroupSucceeds(Arrangement.SUCCESSFUL_ADDITION_RESULT) - .withGetConversationMembersReturning(Arrangement.MEMBERS) + .withGetConversationMembersReturning(Arrangement.MEMBERS.right()) .withAddMembersSucceeds() .withEstablishedCall() .arrange() @@ -148,6 +151,7 @@ class MLSMigratorTest { .withUpdateProtocolReturns() .withFetchConversationSucceeding() .withGetConversationProtocolInfoReturning(Arrangement.MIXED_PROTOCOL_INFO) + .withGetConversationMembersReturning(StorageFailure.DataNotFound.left()) .withEstablishGroupFails() .withoutAnyEstablishedCall() .arrange() @@ -244,10 +248,10 @@ class MLSMigratorTest { }.returns(Either.Right(protocolInfo)) } - suspend fun withGetConversationMembersReturning(members: List) = apply { + suspend fun withGetConversationMembersReturning(result: Either>) = apply { coEvery { conversationRepository.getConversationMembers(any()) - }.returns(Either.Right(members)) + }.returns(result) } suspend fun withFetchConversationSucceeding() = apply {