Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow creating empty MLS GroupConversation [WPB-7099] 🍒 #2870

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal class ConversationGroupRepositoryImpl(
}

when (apiResult) {
is Either.Left -> handleCreateConverstionFailure(
is Either.Left -> handleCreateConversationFailure(
apiResult = apiResult,
usersList = usersList,
name = name,
Expand Down Expand Up @@ -204,7 +204,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
Loading