diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt index eeee60e64da..95db95fd9c1 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt @@ -287,7 +287,7 @@ internal class UserDataSource internal constructor( } else { qualifiedUserIdList .chunked(BATCH_SIZE) - .foldToEitherWhileRight(ListUsersDTO(emptyList(), emptyList())) { chunk, acc -> + .foldToEitherWhileRight(ListUsersDTO(emptyList(), emptyList())) { chunk, usersDTO -> wrapApiRequest { kaliumLogger.d("Fetching ${chunk.size} users") userDetailsApi.getMultipleUsers( @@ -295,9 +295,9 @@ internal class UserDataSource internal constructor( ) }.map { kaliumLogger.d("Found ${it.usersFound.size} users and ${it.usersFailed.size} failed users") - acc.copy( - usersFound = (acc.usersFound + it.usersFound).distinct(), - usersFailed = (acc.usersFailed + it.usersFailed).distinct(), + usersDTO.copy( + usersFound = (usersDTO.usersFound + it.usersFound).distinct(), + usersFailed = (usersDTO.usersFailed + it.usersFailed).distinct(), ) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 0c43e55dd03..2bfd8e2097f 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -2108,7 +2108,7 @@ class UserSessionScope internal constructor( ) val migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase - get() = MigrateFromPersonalToTeamUseCaseImpl(userId, userRepository, invalidateTeamId) + get() = MigrateFromPersonalToTeamUseCaseImpl(userId, userRepository, syncContacts, invalidateTeamId) internal val getProxyCredentials: GetProxyCredentialsUseCase get() = GetProxyCredentialsUseCaseImpl(sessionManager) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt index 5f2ca1c35bf..4911063abdc 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCase.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logic.data.id.TeamId import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.NetworkFailure import com.wire.kalium.logic.data.user.UserRepository +import com.wire.kalium.logic.feature.user.SyncContactsUseCase import com.wire.kalium.logic.functional.fold import com.wire.kalium.network.exceptions.KaliumException @@ -54,6 +55,7 @@ sealed class MigrateFromPersonalToTeamFailure { internal class MigrateFromPersonalToTeamUseCaseImpl internal constructor( private val selfUserId: UserId, private val userRepository: UserRepository, + private val syncContacts: SyncContactsUseCase, private val invalidateTeamId: () -> Unit ) : MigrateFromPersonalToTeamUseCase { override suspend operator fun invoke( @@ -94,7 +96,8 @@ internal class MigrateFromPersonalToTeamUseCaseImpl internal constructor( } }, { user -> userRepository.updateTeamId(selfUserId, TeamId(user.teamId)) - invalidateTeamId() + invalidateTeamId() + syncContacts() MigrateFromPersonalToTeamResult.Success }) } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt index 23f8ce4db9f..8cade1ee962 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/migration/MigrateFromPersonalToTeamUseCaseTest.kt @@ -23,6 +23,7 @@ import com.wire.kalium.logic.NetworkFailure import com.wire.kalium.logic.StorageFailure import com.wire.kalium.logic.data.user.CreateUserTeam import com.wire.kalium.logic.data.user.UserRepository +import com.wire.kalium.logic.feature.user.SyncContactsUseCase import com.wire.kalium.logic.framework.TestUser import com.wire.kalium.logic.functional.Either import com.wire.kalium.network.api.model.ErrorResponse @@ -47,6 +48,7 @@ class MigrateFromPersonalToTeamUseCaseTest { val (arrangement, useCase) = Arrangement() .withUpdateTeamIdReturning(Either.Right(Unit)) .withMigrationSuccess() + .withSyncContactsSuccess() .arrange() val result = useCase(teamName = "teamName") @@ -54,6 +56,10 @@ class MigrateFromPersonalToTeamUseCaseTest { coVerify { arrangement.userRepository.updateTeamId(any(), any()) }.wasInvoked(exactly = once) + + coVerify { + arrangement.syncContacts() }.wasInvoked(exactly = once) + assertTrue(arrangement.isCachedTeamIdInvalidated) assertIs(result) } @@ -107,9 +113,13 @@ class MigrateFromPersonalToTeamUseCaseTest { private class Arrangement { + @Mock val userRepository: UserRepository = mock(UserRepository::class) + @Mock + val syncContacts: SyncContactsUseCase = mock(SyncContactsUseCase::class) + var isCachedTeamIdInvalidated = false suspend fun withMigrationSuccess() = apply { @@ -134,7 +144,6 @@ class MigrateFromPersonalToTeamUseCaseTest { ) ) - suspend fun withMigrationUserNotFoundFailure() = withMigrationReturning( Either.Left( NetworkFailure.ServerMiscommunication( @@ -149,6 +158,10 @@ class MigrateFromPersonalToTeamUseCaseTest { ) ) + suspend fun withSyncContactsSuccess() = apply { + coEvery { syncContacts.invoke() }.returns(Either.Right(Unit)) + } + suspend fun withMigrationNoNetworkFailure() = withMigrationReturning( Either.Left(NetworkFailure.NoNetworkConnection(null)) ) @@ -163,6 +176,7 @@ class MigrateFromPersonalToTeamUseCaseTest { fun arrange() = this to MigrateFromPersonalToTeamUseCaseImpl(selfUserId = TestUser.SELF.id, userRepository = userRepository, + syncContacts = syncContacts, invalidateTeamId = { isCachedTeamIdInvalidated = true })