Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop' into chore…
Browse files Browse the repository at this point in the history
…/bulletproofing-cbox-ccmigration-dev
  • Loading branch information
saleniuk committed Nov 28, 2024
2 parents 5a57a18 + 2e06e37 commit aaa5fe8
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.IsOtherUserE2EIVerifiedUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCase
import com.wire.kalium.logic.feature.featureConfig.FeatureFlagsSyncWorker
import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
import com.wire.kalium.logic.feature.publicuser.GetAllContactsUseCase
import com.wire.kalium.logic.feature.publicuser.GetKnownUserUseCase
import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase
Expand Down Expand Up @@ -240,6 +241,11 @@ class UserModule {
fun provideFeatureFlagsSyncWorker(userScope: UserScope): FeatureFlagsSyncWorker =
userScope.featureFlagsSyncWorker

@ViewModelScoped
@Provides
fun provideIsPersonalToTeamAccountSupportedByBackendUseCase(userScope: UserScope): CanMigrateFromPersonalToTeamUseCase =
userScope.isPersonalToTeamAccountSupportedByBackend

@ViewModelScoped
@Provides
fun provideObserveCertificateRevocationForSelfClientUseCase(userScope: UserScope): ObserveCertificateRevocationForSelfClientUseCase =
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.wire.android.util.ui.WireSessionImageLoader
import com.wire.kalium.logic.feature.client.NeedsToRegisterClientUseCase
import com.wire.kalium.logic.feature.legalhold.LegalHoldStateForSelfUser
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserUseCase
import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collectLatest
Expand All @@ -52,6 +53,7 @@ class HomeViewModel @Inject constructor(
private val dataStore: UserDataStore,
private val getSelf: GetSelfUserUseCase,
private val needsToRegisterClient: NeedsToRegisterClientUseCase,
private val canMigrateFromPersonalToTeam: CanMigrateFromPersonalToTeamUseCase,
private val observeLegalHoldStatusForSelfUser: ObserveLegalHoldStateForSelfUserUseCase,
private val wireSessionImageLoader: WireSessionImageLoader,
private val shouldTriggerMigrationForUser: ShouldTriggerMigrationForUserUserCase,
Expand Down Expand Up @@ -80,15 +82,17 @@ class HomeViewModel @Inject constructor(

private fun observeCreateTeamIndicator() {
viewModelScope.launch {
getSelf().first().let { selfUser ->
val isPersonalUser = selfUser.teamId == null
if (isPersonalUser) {
dataStore.isCreateTeamNoticeRead().collect { isRead ->
homeState = homeState.copy(
shouldShowCreateTeamUnreadIndicator = !isRead
)
}
}
if (!canMigrateFromPersonalToTeam()) {
homeState = homeState.copy(
shouldShowCreateTeamUnreadIndicator = false
)
return@launch
}

dataStore.isCreateTeamNoticeRead().collect { isRead ->
homeState = homeState.copy(
shouldShowCreateTeamUnreadIndicator = !isRead
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private fun SelfUserProfileContent(
.fillMaxHeight()
.scrollable(state = scrollState, orientation = Orientation.Vertical)
) {
if (state.teamName == null) {
if (state.isAbleToMigrateToTeamAccount) {
stickyHeader {
Column(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data class SelfUserProfileState(
val isAvatarLoading: Boolean = false,
val maxAccountsReached: Boolean = false, // todo. cleanup unused code
val isReadOnlyAccount: Boolean = true,
val isAbleToMigrateToTeamAccount: Boolean = false,
val isLoggingOut: Boolean = false,
val legalHoldStatus: LegalHoldUIState = LegalHoldUIState.None,
val accentId: Int = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.wire.kalium.logic.feature.call.usecase.EndCallUseCase
import com.wire.kalium.logic.feature.call.usecase.ObserveEstablishedCallsUseCase
import com.wire.kalium.logic.feature.legalhold.LegalHoldStateForSelfUser
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserUseCase
import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
import com.wire.kalium.logic.feature.team.GetUpdatedSelfTeamUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.IsReadOnlyAccountUseCase
Expand Down Expand Up @@ -84,6 +85,7 @@ class SelfUserProfileViewModel @Inject constructor(
private val dataStore: UserDataStore,
private val getSelf: GetSelfUserUseCase,
private val getSelfTeam: GetUpdatedSelfTeamUseCase,
private val canMigrateFromPersonalToTeam: CanMigrateFromPersonalToTeamUseCase,
private val observeValidAccounts: ObserveValidAccountsUseCase,
private val updateStatus: UpdateSelfAvailabilityStatusUseCase,
private val logout: LogoutUseCase,
Expand All @@ -109,13 +111,19 @@ class SelfUserProfileViewModel @Inject constructor(
init {
viewModelScope.launch {
fetchSelfUser()
checkIfUserAbleToMigrateToTeamAccount()
observeEstablishedCall()
fetchIsReadOnlyAccount()
observeLegalHoldStatus()
markCreateTeamNoticeAsRead()
}
}

private suspend fun checkIfUserAbleToMigrateToTeamAccount() {
val isAbleToMigrateToTeamAccount = canMigrateFromPersonalToTeam() && userProfileState.teamName.isNullOrBlank()
userProfileState = userProfileState.copy(isAbleToMigrateToTeamAccount = isAbleToMigrateToTeamAccount)
}

private suspend fun fetchIsReadOnlyAccount() {
val isReadOnlyAccount = isReadOnlyAccount()
userProfileState = userProfileState.copy(isReadOnlyAccount = isReadOnlyAccount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.wire.android.ui.userprofile.teammigration

import androidx.compose.foundation.text.input.setTextAndSelectAll
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -100,7 +99,6 @@ class TeamMigrationViewModel @Inject constructor(
).let { result ->
when (result) {
is MigrateFromPersonalToTeamResult.Success -> {
teamMigrationState.teamNameTextState.setTextAndSelectAll(result.teamName)
onSuccess()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wire.kalium.logic.data.user.UserAvailabilityStatus
import com.wire.kalium.logic.feature.client.NeedsToRegisterClientUseCase
import com.wire.kalium.logic.feature.legalhold.LegalHoldStateForSelfUser
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserUseCase
import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import io.mockk.MockKAnnotations
import io.mockk.coEvery
Expand Down Expand Up @@ -143,6 +144,9 @@ class HomeViewModelTest {
@MockK
lateinit var analyticsManager: AnonymousAnalyticsManager

@MockK
lateinit var canMigrateFromPersonalToTeam: CanMigrateFromPersonalToTeamUseCase

private val viewModel by lazy {
HomeViewModel(
savedStateHandle = savedStateHandle,
Expand All @@ -153,19 +157,26 @@ class HomeViewModelTest {
observeLegalHoldStatusForSelfUser = observeLegalHoldStatusForSelfUser,
wireSessionImageLoader = wireSessionImageLoader,
shouldTriggerMigrationForUser = shouldTriggerMigrationForUser,
analyticsManager = analyticsManager
analyticsManager = analyticsManager,
canMigrateFromPersonalToTeam = canMigrateFromPersonalToTeam
)
}

init {
MockKAnnotations.init(this, relaxUnitFun = true)
withGetSelf(flowOf(TestUser.SELF_USER))
withCanMigrateFromPersonalToTeamReturning(true)
}

fun withGetSelf(result: Flow<SelfUser>) = apply {
coEvery { getSelf.invoke() } returns result
}

private fun withCanMigrateFromPersonalToTeamReturning(result: Boolean) = apply {
coEvery { canMigrateFromPersonalToTeam.invoke() } returns result
coEvery { dataStore.isCreateTeamNoticeRead() } returns flowOf(false)
}

fun withLegalHoldStatus(result: Flow<LegalHoldStateForSelfUser>) = apply {
coEvery { observeLegalHoldStatusForSelfUser.invoke() } returns result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.wire.kalium.logic.feature.call.usecase.EndCallUseCase
import com.wire.kalium.logic.feature.call.usecase.ObserveEstablishedCallsUseCase
import com.wire.kalium.logic.feature.legalhold.LegalHoldStateForSelfUser
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserUseCase
import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
import com.wire.kalium.logic.feature.team.GetUpdatedSelfTeamUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.IsReadOnlyAccountUseCase
Expand Down Expand Up @@ -101,6 +102,9 @@ class SelfUserProfileViewModelArrangement {
@MockK
lateinit var anonymousAnalyticsManager: AnonymousAnalyticsManager

@MockK
lateinit var canMigrateFromPersonalToTeam: CanMigrateFromPersonalToTeamUseCase

private val viewModel by lazy {
SelfUserProfileViewModel(
selfUserId = TestUser.SELF_USER.id,
Expand All @@ -121,7 +125,8 @@ class SelfUserProfileViewModelArrangement {
notificationManager = notificationManager,
globalDataStore = globalDataStore,
qualifiedIdMapper = qualifiedIdMapper,
anonymousAnalyticsManager = anonymousAnalyticsManager
anonymousAnalyticsManager = anonymousAnalyticsManager,
canMigrateFromPersonalToTeam = canMigrateFromPersonalToTeam
)
}

Expand All @@ -134,6 +139,8 @@ class SelfUserProfileViewModelArrangement {
coEvery { observeValidAccounts.invoke() } returns flowOf(listOf(TestUser.SELF_USER to TestTeam.TEAM))
coEvery { isReadOnlyAccount.invoke() } returns false
coEvery { observeEstablishedCalls.invoke() } returns flowOf(emptyList())
coEvery { observeEstablishedCalls.invoke() } returns flowOf(emptyList())
coEvery { canMigrateFromPersonalToTeam.invoke() } returns true
}

fun withLegalHoldStatus(result: LegalHoldStateForSelfUser) = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ class TeamMigrationViewModelTest {
}

fun withMigrateFromPersonalToTeamSuccess() = apply {
coEvery { migrateFromPersonalToTeam(any()) } returns MigrateFromPersonalToTeamResult.Success(
TEAM_NAME
)
coEvery { migrateFromPersonalToTeam(any()) } returns MigrateFromPersonalToTeamResult.Success
}

fun withMigrateFromPersonalToTeamError() = apply {
Expand Down

0 comments on commit aaa5fe8

Please sign in to comment.