Skip to content

Commit

Permalink
fix: Allow creating empty MLS GroupConversation (#2869)
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow authored Jul 9, 2024
1 parent 596eb02 commit 478ed1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -176,7 +169,7 @@ internal class ConversationGroupRepositoryImpl(
}
}

private suspend fun handleCreateConverstionFailure(
private suspend fun handleCreateConversationFailure(
apiResult: Either.Left<NetworkFailure>,
usersList: List<UserId>,
failedUsersList: List<UserId>,
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 @@ -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"),
Expand All @@ -138,13 +138,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 @@ -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)
}
}

Expand Down

0 comments on commit 478ed1e

Please sign in to comment.