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

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
539cc46
feat: hide personal to team migration feature if not supported by bac…
ohassine Nov 20, 2024
d468507
feat: update kalium reference
ohassine Nov 20, 2024
6c5f913
Merge branch 'develop' into hide-personal-to-team-migration-feature-i…
ohassine Nov 20, 2024
1bc8443
feat: unit test
ohassine Nov 20, 2024
4417ddc
Merge remote-tracking branch 'origin/hide-personal-to-team-migration-…
ohassine Nov 20, 2024
66162d1
chore: address comments
ohassine Nov 21, 2024
af49833
chore: kalium reference
ohassine Nov 21, 2024
3109f20
Merge remote-tracking branch 'origin/develop' into hide-personal-to-t…
ohassine Nov 22, 2024
abe3a39
chore: kalium reference
ohassine Nov 22, 2024
ef4ce7e
chore: kalium reference
ohassine Nov 22, 2024
2c4163c
chore: update kalium reference
ohassine Nov 26, 2024
90330bf
Merge remote-tracking branch 'origin/develop' into hide-personal-to-t…
ohassine Nov 26, 2024
1e77436
chore: Empty-Commit
ohassine Nov 26, 2024
4ac44fd
chore: unit test
ohassine Nov 26, 2024
c10922d
Merge branch 'develop' into hide-personal-to-team-migration-feature-i…
ohassine Nov 26, 2024
0adfb18
chore: unit test
ohassine Nov 26, 2024
9298370
chore: detekt
ohassine Nov 26, 2024
d8512cc
Merge branch 'develop' into hide-personal-to-team-migration-feature-i…
ohassine Nov 26, 2024
2337d1d
chore: update kalium reference
ohassine Nov 26, 2024
56ad181
Merge remote-tracking branch 'origin/hide-personal-to-team-migration-…
ohassine Nov 26, 2024
4cd6d31
chore: unit test
ohassine Nov 28, 2024
33654b1
Merge branch 'develop' into hide-personal-to-team-migration-feature-i…
ohassine Nov 28, 2024
a2f9738
Merge branch 'develop' into hide-personal-to-team-migration-feature-i…
ohassine Nov 28, 2024
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 @@ -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 isPersonalToTeamAccountSupportedByBackend: 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 = 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.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,25 @@ class HomeViewModelTest {
observeLegalHoldStatusForSelfUser = observeLegalHoldStatusForSelfUser,
wireSessionImageLoader = wireSessionImageLoader,
shouldTriggerMigrationForUser = shouldTriggerMigrationForUser,
analyticsManager = analyticsManager
analyticsManager = analyticsManager,
isPersonalToTeamAccountSupportedByBackend = 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
}

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

Expand Down
Loading