diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelector.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelector.kt index 64ca6ef2bf8..ee4b335a197 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelector.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelector.kt @@ -24,7 +24,8 @@ import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.data.user.UserRepository import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap -import com.wire.kalium.logic.functional.fold +import com.wire.kalium.logic.functional.getOrNull +import com.wire.kalium.logic.kaliumLogger internal interface OneOnOneProtocolSelector { suspend fun getProtocolForUser(userId: UserId): Either @@ -41,13 +42,17 @@ internal class OneOnOneProtocolSelectorImpl( return@flatMap Either.Left(CoreFailure.Unknown(error)) } + val teamDefaultProtocol = userConfigRepository.getDefaultProtocol().getOrNull() val selfUserProtocols = selfUser.supportedProtocols.orEmpty() val otherUserProtocols = otherUser.supportedProtocols.orEmpty() - val commonProtocols = userConfigRepository.getDefaultProtocol().fold({ - selfUserProtocols.intersect(otherUserProtocols) - }, { - selfUserProtocols.intersect(listOf(it).toSet()).intersect(otherUserProtocols) - }) + val commonProtocols = selfUserProtocols.intersect(otherUserProtocols) + + kaliumLogger.withTextTag(TAG).d( + "teamDefaultProtocol = $teamDefaultProtocol, " + + "selfUserProtocols = $selfUserProtocols, " + + "otherUserProtocols = $otherUserProtocols, " + + "commonProtocols = $commonProtocols" + ) return when { commonProtocols.contains(SupportedProtocol.MLS) -> Either.Right(SupportedProtocol.MLS) @@ -56,4 +61,8 @@ internal class OneOnOneProtocolSelectorImpl( else -> Either.Left(CoreFailure.NoCommonProtocolFound.SelfNeedToUpdate) } } + + private companion object { + const val TAG = "OneOnOneProtocolSelector" + } } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelectorTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelectorTest.kt index ae3f2cff1b3..7c90ff4dd67 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelectorTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/protocol/OneOnOneProtocolSelectorTest.kt @@ -166,48 +166,6 @@ class OneOnOneProtocolSelectorTest { } } - @Test - fun givenUsersHaveProtocolInCommonButDiffersWithDefaultProtocol_thenShouldReturnNoCommonProtocol() = runTest { - val (_, oneOnOneProtocolSelector) = arrange { - withSelfUserReturning(TestUser.SELF.copy(supportedProtocols = setOf(SupportedProtocol.MLS))) - withUserByIdReturning(Either.Right(TestUser.OTHER.copy(supportedProtocols = setOf(SupportedProtocol.MLS)))) - withGetDefaultProtocolReturning(SupportedProtocol.PROTEUS.right()) - } - - oneOnOneProtocolSelector.getProtocolForUser(TestUser.USER_ID) - .shouldFail { - assertIs(it) - } - } - - @Test - fun givenSelfUserSupportsDefaultProtocolButOtherUserDoesnt_thenShouldReturnNoCommonProtocol() = runTest { - val (_, oneOnOneProtocolSelector) = arrange { - withSelfUserReturning(TestUser.SELF.copy(supportedProtocols = setOf(SupportedProtocol.MLS, SupportedProtocol.PROTEUS))) - withUserByIdReturning(Either.Right(TestUser.OTHER.copy(supportedProtocols = setOf(SupportedProtocol.MLS)))) - withGetDefaultProtocolReturning(SupportedProtocol.PROTEUS.right()) - } - - oneOnOneProtocolSelector.getProtocolForUser(TestUser.USER_ID) - .shouldFail { - assertIs(it) - } - } - - @Test - fun givenSelfUserDoesntSupportsDefaultProtocolButOtherUserDoes_thenShouldReturnNoCommonProtocol() = runTest { - val (_, oneOnOneProtocolSelector) = arrange { - withSelfUserReturning(TestUser.SELF.copy(supportedProtocols = setOf(SupportedProtocol.MLS))) - withUserByIdReturning(Either.Right(TestUser.OTHER.copy(supportedProtocols = setOf(SupportedProtocol.MLS, SupportedProtocol.PROTEUS)))) - withGetDefaultProtocolReturning(SupportedProtocol.PROTEUS.right()) - } - - oneOnOneProtocolSelector.getProtocolForUser(TestUser.USER_ID) - .shouldFail { - assertIs(it) - } - } - @Test fun givenUsersHaveProtocolInCommonIncludingDefaultProtocol_thenShouldReturnDefaultProtocolAsCommonProtocol() = runTest { val (_, oneOnOneProtocolSelector) = arrange {