Skip to content

Commit

Permalink
fix: Allow creating empty MLS GroupConversation [WPB-7099] πŸ’ (#2870) (#…
Browse files Browse the repository at this point in the history
…2872)

* Commit with unresolved merge conflicts

* Fixed cherry-pick issues

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: boris <[email protected]>
Co-authored-by: Boris Safonov <[email protected]>
Co-authored-by: Yamil Medina <[email protected]>
  • Loading branch information
4 people authored Jul 15, 2024
1 parent 9eed6f3 commit 49af73c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal class ConversationGroupRepositoryImpl(
}

when (apiResult) {
is Either.Left -> handleCreateConverstionFailure(
is Either.Left -> handleCreateConversationFailure(
apiResult = apiResult,
usersList = usersList,
name = name,
Expand Down Expand Up @@ -208,7 +208,7 @@ internal class ConversationGroupRepositoryImpl(
}
}

private suspend fun handleCreateConverstionFailure(
private suspend fun handleCreateConversationFailure(
apiResult: Either.Left<NetworkFailure>,
usersList: List<UserId>,
name: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,7 +79,7 @@ class KeyPackageDataSource(
userIds: List<UserId>,
cipherSuite: CipherSuite
): Either<CoreFailure, KeyPackageClaimResult> =
currentClientIdProvider().flatMap { selfClientId ->
currentClientIdProvider().map { selfClientId ->
val failedUsers = mutableSetOf<UserId>()
val claimedKeyPackages = mutableListOf<KeyPackageDTO>()
userIds.forEach { userId ->
Expand All @@ -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<CoreFailure, Unit> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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"),
Expand All @@ -136,13 +136,14 @@ class KeyPackageRepositoryTest {

val result = keyPackageRepository.claimKeyPackages(usersWithout.toList(), CIPHER_SUITE)

result.shouldFail { failure ->
assertIs<CoreFailure.MissingKeyPackages>(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()
Expand All @@ -151,8 +152,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)
}
}

Expand Down

0 comments on commit 49af73c

Please sign in to comment.