-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle adding participants while some of their backends are dow…
…n (WPB-462) (#1900) * feat: add mapping of hasUnreachableDomainsError and prepare handling for retry * feat: add mapping of hasUnreachableDomainsError and prepare handling for retry * feat: add retry and mapper of failed domains * feat: add retry and mapper of failed domains * feat: add retry mechanism to attempt with valid users * feat: add retry mechanism to attempt with valid users * feat: add retry mechanism to attempt with valid users * feat: add retry mechanism to attempt with valid users * feat: add retry mechanism to attempt with valid users * feat: cleanup * feat: add system message creation of failed to add * feat: test cov * feat: test cov * feat: test coverage * feat: test coverage, code cleanup * feat: test coverage, code cleanup
- Loading branch information
1 parent
0eeaf2c
commit 82a1705
Showing
15 changed files
with
315 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...c/commonMain/kotlin/com/wire/kalium/logic/data/conversation/AddingMembersFailureMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.data.conversation | ||
|
||
import com.wire.kalium.logic.NetworkFailure | ||
import com.wire.kalium.logic.data.user.UserId | ||
|
||
internal interface AddingMembersFailureMapper { | ||
/** | ||
* Will map the [initialUsersIds] and split accordingly excluding users with domain failures. | ||
* @param initialUsersIds the list of users that were initially requested to be added to the conversation | ||
* @param federatedBackendFailure the [NetworkFailure.FederatedBackendFailure] that contains the domains that failed | ||
* @param previousUserIdsExcluded the previous attempt of list of users that cannot be added to the conversation | ||
*/ | ||
fun mapToUsersRequestState( | ||
initialUsersIds: List<UserId>, | ||
federatedBackendFailure: NetworkFailure.FederatedBackendFailure, | ||
previousUserIdsExcluded: Set<UserId> = emptySet(), | ||
): AddingMembersRequestState | ||
} | ||
|
||
internal class AddingMembersFailureMapperImpl : AddingMembersFailureMapper { | ||
override fun mapToUsersRequestState( | ||
initialUsersIds: List<UserId>, | ||
federatedBackendFailure: NetworkFailure.FederatedBackendFailure, | ||
previousUserIdsExcluded: Set<UserId> | ||
): AddingMembersRequestState { | ||
val domainsToExclude = federatedBackendFailure.domains | ||
// splitting the initialUsersIds into users with failures[true] and users without failures[false] | ||
val groupedUsersWithFailure = initialUsersIds.groupBy { | ||
domainsToExclude.contains(it.domain) | ||
} | ||
return AddingMembersRequestState( | ||
usersThatCanBeAdded = groupedUsersWithFailure[false]?.toSet().orEmpty(), | ||
usersThatCannotBeAdded = groupedUsersWithFailure[true]?.toSet().orEmpty() + previousUserIdsExcluded | ||
) | ||
} | ||
} | ||
|
||
data class AddingMembersRequestState( | ||
val usersThatCanBeAdded: Set<UserId>, | ||
val usersThatCannotBeAdded: Set<UserId>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...mmonTest/kotlin/com/wire/kalium/logic/data/conversation/AddingMembersFailureMapperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.data.conversation | ||
|
||
import com.wire.kalium.logic.NetworkFailure | ||
import com.wire.kalium.logic.framework.TestUser | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class AddingMembersFailureMapperTest { | ||
|
||
private val addingMembersFailureMapper = AddingMembersFailureMapperImpl() | ||
|
||
@Test | ||
fun givenUsersIdsAndDomainsError_whenMapping_thenShouldSplitIntoValidAndNotValidUserIds() { | ||
// When | ||
val mappedRequestState = addingMembersFailureMapper.mapToUsersRequestState( | ||
initialUsersIds = initialUserIdList, | ||
federatedBackendFailure = NetworkFailure.FederatedBackendFailure("federated-label", unreachableDomains) | ||
) | ||
|
||
// Then | ||
assertEquals(TestUser.OTHER_USER_ID, mappedRequestState.usersThatCanBeAdded.first()) | ||
assertEquals(TestUser.OTHER_FEDERATED_USER_ID, mappedRequestState.usersThatCannotBeAdded.first()) | ||
} | ||
|
||
@Test | ||
fun givenUsersIdsADomainsErrorAndPreviousFailedIds_whenMapping_thenShouldSplitConsideringPreviousFailedIds() { | ||
// When | ||
val mappedRequestState = addingMembersFailureMapper.mapToUsersRequestState( | ||
initialUsersIds = initialUserIdList, | ||
federatedBackendFailure = NetworkFailure.FederatedBackendFailure("federated-label", unreachableDomains), | ||
previousUserIdsExcluded = previousFailedIds | ||
) | ||
|
||
// Then | ||
assertEquals(TestUser.OTHER_USER_ID, mappedRequestState.usersThatCanBeAdded.first()) | ||
assertEquals(2, mappedRequestState.usersThatCannotBeAdded.size) | ||
assertTrue { | ||
mappedRequestState.usersThatCannotBeAdded.containsAll( | ||
listOf( | ||
TestUser.OTHER_FEDERATED_USER_ID, | ||
TestUser.OTHER_FEDERATED_USER_ID_2 | ||
) | ||
) | ||
} | ||
} | ||
|
||
private companion object { | ||
val initialUserIdList = listOf(TestUser.OTHER_USER_ID, TestUser.OTHER_FEDERATED_USER_ID) | ||
val previousFailedIds = setOf(TestUser.OTHER_FEDERATED_USER_ID_2) | ||
val unreachableDomains = listOf("otherDomain") | ||
} | ||
} |
Oops, something went wrong.