diff --git a/app/src/main/kotlin/com/wire/android/di/accountScoped/UserModule.kt b/app/src/main/kotlin/com/wire/android/di/accountScoped/UserModule.kt index f1d6baba694..e4ed7d01bfa 100644 --- a/app/src/main/kotlin/com/wire/android/di/accountScoped/UserModule.kt +++ b/app/src/main/kotlin/com/wire/android/di/accountScoped/UserModule.kt @@ -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 @@ -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 = diff --git a/app/src/main/kotlin/com/wire/android/ui/home/HomeViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/HomeViewModel.kt index 7d0444dea44..4e4667ad186 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/HomeViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/HomeViewModel.kt @@ -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 @@ -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, @@ -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 + ) } } } diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileScreen.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileScreen.kt index dd913cfac34..70a44582e10 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileScreen.kt @@ -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 diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileState.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileState.kt index 1e763c7c6a1..c5ffb5c647a 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileState.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileState.kt @@ -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 diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModel.kt index 85f41060d40..2ae4c272fd6 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModel.kt @@ -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 @@ -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, @@ -109,6 +111,7 @@ class SelfUserProfileViewModel @Inject constructor( init { viewModelScope.launch { fetchSelfUser() + checkIfUserAbleToMigrateToTeamAccount() observeEstablishedCall() fetchIsReadOnlyAccount() observeLegalHoldStatus() @@ -116,6 +119,11 @@ class SelfUserProfileViewModel @Inject constructor( } } + 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) diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt index b8652aa171b..9b8fefd2dc9 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt @@ -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 @@ -100,7 +99,6 @@ class TeamMigrationViewModel @Inject constructor( ).let { result -> when (result) { is MigrateFromPersonalToTeamResult.Success -> { - teamMigrationState.teamNameTextState.setTextAndSelectAll(result.teamName) onSuccess() } diff --git a/app/src/test/kotlin/com/wire/android/ui/home/HomeViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/HomeViewModelTest.kt index ba7d91972ce..28198da601e 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/HomeViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/HomeViewModelTest.kt @@ -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 @@ -143,6 +144,9 @@ class HomeViewModelTest { @MockK lateinit var analyticsManager: AnonymousAnalyticsManager + @MockK + lateinit var canMigrateFromPersonalToTeam: CanMigrateFromPersonalToTeamUseCase + private val viewModel by lazy { HomeViewModel( savedStateHandle = savedStateHandle, @@ -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) = 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) = apply { coEvery { observeLegalHoldStatusForSelfUser.invoke() } returns result } diff --git a/app/src/test/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModelArrangement.kt b/app/src/test/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModelArrangement.kt index 5c58262e8de..c9ef3d66040 100644 --- a/app/src/test/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModelArrangement.kt +++ b/app/src/test/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileViewModelArrangement.kt @@ -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 @@ -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, @@ -121,7 +125,8 @@ class SelfUserProfileViewModelArrangement { notificationManager = notificationManager, globalDataStore = globalDataStore, qualifiedIdMapper = qualifiedIdMapper, - anonymousAnalyticsManager = anonymousAnalyticsManager + anonymousAnalyticsManager = anonymousAnalyticsManager, + canMigrateFromPersonalToTeam = canMigrateFromPersonalToTeam ) } @@ -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 { diff --git a/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt index 4def3b04039..efec0349927 100644 --- a/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt @@ -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 { diff --git a/kalium b/kalium index c7b96a2584d..786a7b83e84 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit c7b96a2584d6cba1619501b917a90b757785b7ac +Subproject commit 786a7b83e84663909c6c40b3f6c72263fe935661