Skip to content

Commit

Permalink
feat: show Guest label for personal users after migration in conversa…
Browse files Browse the repository at this point in the history
…tions screen
  • Loading branch information
ohassine committed Jan 2, 2025
1 parent 7f1da82 commit 48aad03
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,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 @@ -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)
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

0 comments on commit 48aad03

Please sign in to comment.