From e7c7fa209f0685cb465c9e53f33b9e1b3e227a4a Mon Sep 17 00:00:00 2001 From: boris Date: Mon, 24 Jun 2024 12:15:23 +0300 Subject: [PATCH 1/3] fix: Split NoCommonProtocol error (#2832) * fix: Split NoCommonProtocol error * Fixed style --- .../kotlin/com/wire/kalium/logic/CoreFailure.kt | 11 ++++++++++- .../protocol/OneOnOneProtocolSelector.kt | 3 ++- ...etOrCreateOneToOneConversationUseCaseTest.kt | 2 +- .../protocol/OneOnOneProtocolSelectorTest.kt | 17 ++++++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) 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 b9662a8a77c..316625b9526 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt @@ -117,7 +117,16 @@ sealed interface CoreFailure { * No common Protocol found in order to establish a conversation between parties. * Could be, for example, that the desired user only supports Proteus, but we only support MLS. */ - data object NoCommonProtocolFound : FeatureFailure() + sealed class NoCommonProtocolFound : FeatureFailure() { + /** + * SelfClient needs to update to support MLS + */ + data object SelfNeedToUpdate : NoCommonProtocolFound() + /** + * Other User needs to update to support MLS + */ + data object OtherNeedToUpdate : NoCommonProtocolFound() + } } sealed class NetworkFailure : CoreFailure { 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 d0608b8abdd..64ca6ef2bf8 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 @@ -52,7 +52,8 @@ internal class OneOnOneProtocolSelectorImpl( return when { commonProtocols.contains(SupportedProtocol.MLS) -> Either.Right(SupportedProtocol.MLS) commonProtocols.contains(SupportedProtocol.PROTEUS) -> Either.Right(SupportedProtocol.PROTEUS) - else -> Either.Left(CoreFailure.NoCommonProtocolFound) + selfUserProtocols.contains(SupportedProtocol.MLS) -> Either.Left(CoreFailure.NoCommonProtocolFound.OtherNeedToUpdate) + else -> Either.Left(CoreFailure.NoCommonProtocolFound.SelfNeedToUpdate) } } } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/GetOrCreateOneToOneConversationUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/GetOrCreateOneToOneConversationUseCaseTest.kt index 377d2712b51..417c56e6672 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/GetOrCreateOneToOneConversationUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/GetOrCreateOneToOneConversationUseCaseTest.kt @@ -69,7 +69,7 @@ class GetOrCreateOneToOneConversationUseCaseTest { val (_, useCase) = arrange { withObserveOneToOneConversationWithOtherUserReturning(Either.Left(StorageFailure.DataNotFound)) withUserByIdReturning(OTHER_USER.right()) - withResolveOneOnOneConversationWithUserReturning(Either.Left(CoreFailure.NoCommonProtocolFound)) + withResolveOneOnOneConversationWithUserReturning(Either.Left(CoreFailure.NoCommonProtocolFound.SelfNeedToUpdate)) } // when 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 134e4af7086..50623732ab5 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 @@ -147,7 +147,22 @@ class OneOnOneProtocolSelectorTest { oneOnOneProtocolSelector.getProtocolForUser(TestUser.USER_ID) .shouldFail { - assertIs(it) + assertIs(it) + } + } + + @Test + fun givenUsersHaveNoProtocolInCommon_thenShouldReturnNoCommonProtocol_2() = runTest { + val failure = StorageFailure.DataNotFound + val (_, oneOnOneProtocolSelector) = arrange { + withSelfUserReturning(TestUser.SELF.copy(supportedProtocols = setOf(SupportedProtocol.PROTEUS))) + withUserByIdReturning(Either.Right(TestUser.OTHER.copy(supportedProtocols = setOf(SupportedProtocol.MLS)))) + withGetDefaultProtocolReturning(failure.left()) + } + + oneOnOneProtocolSelector.getProtocolForUser(TestUser.USER_ID) + .shouldFail { + assertIs(it) } } From 7b63900a2fbad43d67109931580e0a1c386d091b Mon Sep 17 00:00:00 2001 From: Boris Safonov Date: Tue, 25 Jun 2024 12:15:19 +0300 Subject: [PATCH 2/3] Empty-Commit From 40056cced670071541f472ece34d1a9888113122 Mon Sep 17 00:00:00 2001 From: Boris Safonov Date: Tue, 25 Jun 2024 14:06:14 +0300 Subject: [PATCH 3/3] Fix codestyle --- logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt | 1 + 1 file changed, 1 insertion(+) 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 316625b9526..6ce16825226 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt @@ -122,6 +122,7 @@ sealed interface CoreFailure { * SelfClient needs to update to support MLS */ data object SelfNeedToUpdate : NoCommonProtocolFound() + /** * Other User needs to update to support MLS */