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: Hide personal to team migration feature if not supported by backend (WPB-12022) #3650

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
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.IsPersonalToTeamAccountSupportedByBackendUseCase
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): IsPersonalToTeamAccountSupportedByBackendUseCase =
userScope.isPersonalToTeamAccountSupportedByBackend

@ViewModelScoped
@Provides
fun provideObserveCertificateRevocationForSelfClientUseCase(userScope: UserScope): ObserveCertificateRevocationForSelfClientUseCase =
Expand Down
8 changes: 8 additions & 0 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.IsPersonalToTeamAccountSupportedByBackendUseCase
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 isPersonalToTeamAccountSupportedByBackend: IsPersonalToTeamAccountSupportedByBackendUseCase,
private val observeLegalHoldStatusForSelfUser: ObserveLegalHoldStateForSelfUserUseCase,
private val wireSessionImageLoader: WireSessionImageLoader,
private val shouldTriggerMigrationForUser: ShouldTriggerMigrationForUserUserCase,
Expand Down Expand Up @@ -80,6 +82,12 @@ class HomeViewModel @Inject constructor(

private fun observeCreateTeamIndicator() {
viewModelScope.launch {
if (!isPersonalToTeamAccountSupportedByBackend()) {
homeState = homeState.copy(
shouldShowCreateTeamUnreadIndicator = false
)
return@launch
}
getSelf().first().let { selfUser ->
val isPersonalUser = selfUser.teamId == null
if (isPersonalUser) {
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.IsPersonalToTeamAccountSupportedByBackendUseCase
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 isPersonalToTeamAccountSupportedByBackend: IsPersonalToTeamAccountSupportedByBackendUseCase,
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 = isPersonalToTeamAccountSupportedByBackend() && userProfileState.teamName.isNullOrBlank()
userProfileState = userProfileState.copy(isAbleToMigrateToTeamAccount = isAbleToMigrateToTeamAccount)
ohassine marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -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.IsPersonalToTeamAccountSupportedByBackendUseCase
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 isPersonalToTeamAccountSupportedByBackend: IsPersonalToTeamAccountSupportedByBackendUseCase

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

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

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

fun withIsPersonalToTeamAccountSupportedByBackendReturning(result: Boolean) = apply {
coEvery { isPersonalToTeamAccountSupportedByBackend.invoke() } returns result
}

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.IsPersonalToTeamAccountSupportedByBackendUseCase
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 isPersonalToTeamAccountSupportedByBackend: IsPersonalToTeamAccountSupportedByBackendUseCase

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,
isPersonalToTeamAccountSupportedByBackend = isPersonalToTeamAccountSupportedByBackend
)
}

Expand Down
Loading