From 478ed1e7d8ee072a04f0858dee050a2134530609 Mon Sep 17 00:00:00 2001 From: boris Date: Tue, 9 Jul 2024 15:40:22 +0300 Subject: [PATCH] fix: Allow creating empty MLS GroupConversation (#2869) --- .../conversation/ConversationGroupRepository.kt | 15 ++++----------- .../logic/data/keypackage/KeyPackageRepository.kt | 9 +++------ .../data/keypackage/KeyPackageRepositoryTest.kt | 14 ++++++++------ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepository.kt index fd8d4316635..30e02bc0415 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepository.kt @@ -119,16 +119,9 @@ internal class ConversationGroupRepositoryImpl( } when (apiResult) { - is Either.Left -> handleCreateConverstionFailure(apiResult, usersList, failedUsersList, name, options) - - is Either.Right -> { - handleCreateConversationSuccess( - apiResult, - usersList, - failedUsersList, - selfTeamId - ) - } + is Either.Left -> handleCreateConversationFailure(apiResult, usersList, failedUsersList, name, options) + + is Either.Right -> handleCreateConversationSuccess(apiResult, usersList, failedUsersList, selfTeamId) } } @@ -176,7 +169,7 @@ internal class ConversationGroupRepositoryImpl( } } - private suspend fun handleCreateConverstionFailure( + private suspend fun handleCreateConversationFailure( apiResult: Either.Left, usersList: List, failedUsersList: List, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepository.kt index eefe69da366..56ad144486c 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepository.kt @@ -30,6 +30,7 @@ import com.wire.kalium.logic.data.user.UserId 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.map import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.logic.wrapMLSRequest import com.wire.kalium.network.api.base.authenticated.keypackage.KeyPackageApi @@ -78,7 +79,7 @@ class KeyPackageDataSource( userIds: List, cipherSuite: CipherSuite ): Either = - currentClientIdProvider().flatMap { selfClientId -> + currentClientIdProvider().map { selfClientId -> val failedUsers = mutableSetOf() val claimedKeyPackages = mutableListOf() userIds.forEach { userId -> @@ -99,11 +100,7 @@ class KeyPackageDataSource( } } - if (claimedKeyPackages.isEmpty() && failedUsers.isNotEmpty()) { - Either.Left(CoreFailure.MissingKeyPackages(failedUsers)) - } else { - Either.Right(KeyPackageClaimResult(claimedKeyPackages, failedUsers)) - } + KeyPackageClaimResult(claimedKeyPackages, failedUsers) } override suspend fun uploadNewKeyPackages(clientId: ClientId, amount: Int): Either = diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepositoryTest.kt index f9907617bf7..cd40feb1fb5 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepositoryTest.kt @@ -123,7 +123,7 @@ class KeyPackageRepositoryTest { } @Test - fun givenAllUsersHaveNoKeyPackagesAvailable_whenClaimingKeyPackagesFromMultipleUsers_thenSuccessFailWithMissingKeyPackages() = runTest { + fun givenAllUsersHaveNoKeyPackagesAvailable_whenClaimingKeyPackagesFromMultipleUsers_thenSuccessWitheEmptySuccessKeyPackages() = runTest { val usersWithout = setOf( Arrangement.USER_ID.copy(value = "missingKP"), Arrangement.USER_ID.copy(value = "alsoMissingKP"), @@ -138,13 +138,14 @@ class KeyPackageRepositoryTest { val result = keyPackageRepository.claimKeyPackages(usersWithout.toList(), CIPHER_SUITE) - result.shouldFail { failure -> - assertIs(failure) + result.shouldSucceed { keyPackages -> + assertEquals(emptyList(), keyPackages.successfullyFetchedKeyPackages) + assertEquals(usersWithout, keyPackages.usersWithoutKeyPackagesAvailable) } } @Test - fun givenUserWithNoKeyPackages_whenClaimingKeyPackagesFromSingleUser_thenResultShouldFailWithError() = runTest { + fun givenUserWithNoKeyPackages_whenClaimingKeyPackagesFromSingleUser_thenSuccessWitheEmptySuccessKeyPackages() = runTest { val (_, keyPackageRepository) = Arrangement() .withCurrentClientId() @@ -153,8 +154,9 @@ class KeyPackageRepositoryTest { val result = keyPackageRepository.claimKeyPackages(listOf(Arrangement.USER_ID), CIPHER_SUITE) - result.shouldFail { failure -> - assertEquals(CoreFailure.MissingKeyPackages(setOf(Arrangement.USER_ID)), failure) + result.shouldSucceed { keyPackages -> + assertEquals(emptyList(), keyPackages.successfullyFetchedKeyPackages) + assertEquals(setOf(Arrangement.USER_ID), keyPackages.usersWithoutKeyPackagesAvailable) } }