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

feat: Sync other users after personal to team migration - cherrypick (WPB-14871) 🍒 #3207

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 @@ -285,17 +285,17 @@ 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(
ListUserRequest.qualifiedIds(chunk.map { userId -> userId.toApi() })
)
}.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(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -94,7 +96,8 @@ internal class MigrateFromPersonalToTeamUseCaseImpl internal constructor(
}
}, { user ->
userRepository.updateTeamId(selfUserId, TeamId(user.teamId))
invalidateTeamId()
invalidateTeamId()
syncContacts()
MigrateFromPersonalToTeamResult.Success
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,13 +48,18 @@ class MigrateFromPersonalToTeamUseCaseTest {
val (arrangement, useCase) = Arrangement()
.withUpdateTeamIdReturning(Either.Right(Unit))
.withMigrationSuccess()
.withSyncContactsSuccess()
.arrange()

val result = useCase(teamName = "teamName")

coVerify {
arrangement.userRepository.updateTeamId(any(), any())
}.wasInvoked(exactly = once)

coVerify {
arrangement.syncContacts() }.wasInvoked(exactly = once)

assertTrue(arrangement.isCachedTeamIdInvalidated)
assertIs<MigrateFromPersonalToTeamResult.Success>(result)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -134,7 +144,6 @@ class MigrateFromPersonalToTeamUseCaseTest {
)
)


suspend fun withMigrationUserNotFoundFailure() = withMigrationReturning(
Either.Left(
NetworkFailure.ServerMiscommunication(
Expand All @@ -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))
)
Expand All @@ -163,6 +176,7 @@ class MigrateFromPersonalToTeamUseCaseTest {

fun arrange() = this to MigrateFromPersonalToTeamUseCaseImpl(selfUserId = TestUser.SELF.id,
userRepository = userRepository,
syncContacts = syncContacts,
invalidateTeamId = {
isCachedTeamIdInvalidated = true
})
Expand Down
Loading