Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mls-migration): set correct CS when Kalium start migration (WPB-9638) 🍒 🍒 #2846

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ internal class MLSConversationDataSource(
allowPartialMemberList: Boolean = false,
): Either<CoreFailure, MLSAdditionResult> = 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) {
Expand Down Expand Up @@ -598,6 +599,7 @@ internal class MLSConversationDataSource(
externalSenders: ByteArray,
allowPartialMemberList: Boolean = false,
): Either<CoreFailure, MLSAdditionResult> = withContext(serialDispatcher) {
kaliumLogger.d("establish MLS group: $groupID")
mlsClientProvider.getMLSClient().flatMap { mlsClient ->
wrapMLSRequest {
mlsClient.createConversation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -148,6 +151,7 @@ class MLSMigratorTest {
.withUpdateProtocolReturns()
.withFetchConversationSucceeding()
.withGetConversationProtocolInfoReturning(Arrangement.MIXED_PROTOCOL_INFO)
.withGetConversationMembersReturning(StorageFailure.DataNotFound.left())
.withEstablishGroupFails()
.withoutAnyEstablishedCall()
.arrange()
Expand Down Expand Up @@ -244,10 +248,10 @@ class MLSMigratorTest {
}.returns(Either.Right(protocolInfo))
}

suspend fun withGetConversationMembersReturning(members: List<UserId>) = apply {
suspend fun withGetConversationMembersReturning(result: Either<StorageFailure, List<UserId>>) = apply {
coEvery {
conversationRepository.getConversationMembers(any())
}.returns(Either.Right(members))
}.returns(result)
}

suspend fun withFetchConversationSucceeding() = apply {
Expand Down
Loading