From 32b9731f3da4fb1d3b173abcfc14dc25c8c5b17a Mon Sep 17 00:00:00 2001 From: ohassine Date: Mon, 9 Dec 2024 17:18:52 +0100 Subject: [PATCH 1/7] feat: Wrong URL when opening team management after migration --- .../com/wire/android/di/CoreLogicModule.kt | 10 +++++-- .../userprofile/self/SelfUserProfileScreen.kt | 5 ++++ .../self/SelfUserProfileViewModel.kt | 6 ++--- .../teammigration/TeamMigrationState.kt | 2 ++ .../teammigration/TeamMigrationViewModel.kt | 27 ++++++++++++++++++- .../step4/TeamMigrationDoneStepScreen.kt | 9 ++++--- app/src/main/res/values/strings.xml | 1 - 7 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt b/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt index 3bdf323e37e..01e0ea54c89 100644 --- a/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt +++ b/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt @@ -498,6 +498,12 @@ class UseCaseModule { fun provideMigrateFromPersonalToTeamUseCase( @KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId - ) = - coreLogic.getSessionScope(currentAccount).migrateFromPersonalToTeam + ) = coreLogic.getSessionScope(currentAccount).migrateFromPersonalToTeam + + @ViewModelScoped + @Provides + fun provideGetTeamUrlUseCase( + @KaliumCoreLogic coreLogic: CoreLogic, + @CurrentAccount currentAccount: UserId + ) = coreLogic.getSessionScope(currentAccount).getTeamUrlUseCase } 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 e09da4b1532..628b9107c6b 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 @@ -118,6 +118,11 @@ fun SelfUserProfileScreen( ) { val legalHoldSubjectDialogState = rememberVisibilityState() + LaunchedEffect(Unit) { + // Check if the user is able to migrate to a team account, every time the screen is shown + viewModelSelf.checkIfUserAbleToMigrateToTeamAccount() + } + SelfUserProfileContent( state = viewModelSelf.userProfileState, onCloseClick = navigator::navigateBack, 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 7ea1e925b6b..d2cce6e052a 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 @@ -109,7 +109,6 @@ class SelfUserProfileViewModel @Inject constructor( init { viewModelScope.launch { fetchSelfUser() - checkIfUserAbleToMigrateToTeamAccount() observeEstablishedCall() fetchIsReadOnlyAccount() observeLegalHoldStatus() @@ -117,9 +116,8 @@ class SelfUserProfileViewModel @Inject constructor( } } - private suspend fun checkIfUserAbleToMigrateToTeamAccount() { - val isAbleToMigrateToTeamAccount = canMigrateFromPersonalToTeam() && userProfileState.teamName.isNullOrBlank() - userProfileState = userProfileState.copy(isAbleToMigrateToTeamAccount = isAbleToMigrateToTeamAccount) + suspend fun checkIfUserAbleToMigrateToTeamAccount() { + userProfileState = userProfileState.copy(isAbleToMigrateToTeamAccount = canMigrateFromPersonalToTeam()) } private suspend fun fetchIsReadOnlyAccount() { diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationState.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationState.kt index be2d3d9625e..8feb6d1708e 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationState.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationState.kt @@ -24,5 +24,7 @@ data class TeamMigrationState( val teamNameTextState: TextFieldState = TextFieldState(), val shouldShowMigrationLeaveDialog: Boolean = false, val currentStep: Int = 0, + val username: String = "", + val teamUrl: String = "", val migrationFailure: MigrateFromPersonalToTeamFailure? = null ) 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 b4080251aa6..1c527b15d76 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 @@ -24,6 +24,8 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.wire.android.feature.analytics.AnonymousAnalyticsManager import com.wire.android.feature.analytics.model.AnalyticsEvent +import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase +import com.wire.kalium.logic.feature.user.GetSelfUserUseCase import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamFailure import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamResult import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamUseCase @@ -34,12 +36,19 @@ import javax.inject.Inject @HiltViewModel class TeamMigrationViewModel @Inject constructor( private val anonymousAnalyticsManager: AnonymousAnalyticsManager, - private val migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase + private val migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase, + private val getSelfUser: GetSelfUserUseCase, + private val getTeamUrl: GetTeamUrlUseCase, ) : ViewModel() { var teamMigrationState by mutableStateOf(TeamMigrationState()) private set + init { + setUsername() + setTeamUrl() + } + fun showMigrationLeaveDialog() { teamMigrationState = teamMigrationState.copy(shouldShowMigrationLeaveDialog = true) } @@ -117,4 +126,20 @@ class TeamMigrationViewModel @Inject constructor( private fun onMigrationFailure(failure: MigrateFromPersonalToTeamFailure) { teamMigrationState = teamMigrationState.copy(migrationFailure = failure) } + + private fun setUsername() { + viewModelScope.launch { + getSelfUser().collect { selfUser -> + selfUser.name?.let { + teamMigrationState = teamMigrationState.copy(username = it) + } + } + } + } + + private fun setTeamUrl() { + viewModelScope.launch { + teamMigrationState = teamMigrationState.copy(teamUrl = getTeamUrl()) + } + } } diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step4/TeamMigrationDoneStepScreen.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step4/TeamMigrationDoneStepScreen.kt index 2f582d61aa3..9cfbd4bc63e 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step4/TeamMigrationDoneStepScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step4/TeamMigrationDoneStepScreen.kt @@ -65,7 +65,6 @@ fun TeamMigrationDoneStepScreen( ) { val context = LocalContext.current - val teamManagementUrl = stringResource(R.string.url_team_management) TeamMigrationDoneStepContent( onBackToWireClicked = { teamMigrationViewModel.sendPersonalTeamCreationFlowCompletedEvent( @@ -79,11 +78,14 @@ fun TeamMigrationDoneStepScreen( ) }, onOpenTeamManagementClicked = { + val teamManagementUrl = teamMigrationViewModel.teamMigrationState.teamUrl + teamMigrationViewModel.sendPersonalTeamCreationFlowCompletedEvent( modalOpenTeamManagementButtonClicked = true ) CustomTabsHelper.launchUrl(context, teamManagementUrl) }, + username = teamMigrationViewModel.teamMigrationState.username, teamName = teamMigrationViewModel.teamMigrationState.teamNameTextState.text.toString() ) @@ -98,6 +100,7 @@ fun TeamMigrationDoneStepScreen( private fun TeamMigrationDoneStepContent( onBackToWireClicked: () -> Unit, onOpenTeamManagementClicked: () -> Unit, + username: String, teamName: String, modifier: Modifier = Modifier ) { @@ -130,7 +133,7 @@ private fun TeamMigrationDoneStepContent( bottom = dimensions().spacing56x ) .align(alignment = Alignment.CenterHorizontally), - text = stringResource(R.string.personal_to_team_migration_done_step, teamName), + text = stringResource(R.string.personal_to_team_migration_done_step, username), style = MaterialTheme.wireTypography.title01, color = colorsScheme().onBackground ) @@ -187,6 +190,6 @@ private fun TeamMigrationDoneStepContent( @Composable private fun TeamMigrationDoneStepScreenPreview() { WireTheme { - TeamMigrationDoneStepContent({}, {}, teamName = "teamName") + TeamMigrationDoneStepContent({}, {}, username = "John", teamName = "teamName") } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index de630702afe..1659c946c5a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -273,7 +273,6 @@ https://support.wire.com/hc/articles/207859815 https://support.wire.com/hc/articles/360002855557 https://wire.com/pricing - https://teams.wire.com/ Vault Archive From e5c851ba204011ff817e302dd519f3047ccd5652 Mon Sep 17 00:00:00 2001 From: ohassine Date: Mon, 9 Dec 2024 17:19:25 +0100 Subject: [PATCH 2/7] feat: kalium reference --- kalium | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kalium b/kalium index d8b69f1202e..bbdb00d6156 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit d8b69f1202e0ea88889c98bf1e2f9cd5016d197c +Subproject commit bbdb00d6156df0e5bccea99818ec7dc85bbd7be3 From 0990590d71230e8b81ffa56c1806c136a08721a5 Mon Sep 17 00:00:00 2001 From: ohassine Date: Mon, 9 Dec 2024 17:32:49 +0100 Subject: [PATCH 3/7] feat: test --- .../teammigration/TeamMigrationViewModelTest.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 42a7a926e05..e76498855e9 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 @@ -22,6 +22,8 @@ import com.wire.android.config.CoroutineTestExtension import com.wire.android.feature.analytics.AnonymousAnalyticsManager import com.wire.android.feature.analytics.model.AnalyticsEvent import com.wire.kalium.logic.NetworkFailure +import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase +import com.wire.kalium.logic.feature.user.GetSelfUserUseCase import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamFailure import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamResult import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamUseCase @@ -251,6 +253,12 @@ class TeamMigrationViewModelTest { @MockK lateinit var migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase + @MockK + lateinit var getSelfUser: GetSelfUserUseCase + + @MockK + lateinit var getTeamUrl: GetTeamUrlUseCase + init { MockKAnnotations.init(this, relaxUnitFun = true) } @@ -258,6 +266,8 @@ class TeamMigrationViewModelTest { fun arrange() = this to TeamMigrationViewModel( anonymousAnalyticsManager = anonymousAnalyticsManager, migrateFromPersonalToTeam = migrateFromPersonalToTeam, + getSelfUser = getSelfUser, + getTeamUrl = getTeamUrl ).also { viewModel -> viewModel.teamMigrationState.teamNameTextState.setTextAndPlaceCursorAtEnd(TEAM_NAME) } From 4ea2d65a9961a8e139004ebd2ef069e08adc4505 Mon Sep 17 00:00:00 2001 From: ohassine Date: Wed, 11 Dec 2024 17:07:16 +0100 Subject: [PATCH 4/7] chore: revert unit test --- .../ui/userprofile/teammigration/TeamMigrationViewModelTest.kt | 3 +++ 1 file changed, 3 insertions(+) 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 e76498855e9..fcaf3011bb8 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 @@ -33,6 +33,7 @@ import io.mockk.coVerify import io.mockk.impl.annotations.MockK import io.mockk.mockk import io.mockk.verify +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.amshove.kluent.internal.assertEquals import org.junit.jupiter.api.Assertions @@ -261,6 +262,8 @@ class TeamMigrationViewModelTest { init { MockKAnnotations.init(this, relaxUnitFun = true) + coEvery { getSelfUser() } returns flowOf() + coEvery { getTeamUrl() } returns "TeamUrl" } fun arrange() = this to TeamMigrationViewModel( From 5524868599f4da56567ceb576e7f721ed818c08b Mon Sep 17 00:00:00 2001 From: ohassine Date: Tue, 31 Dec 2024 10:02:43 +0100 Subject: [PATCH 5/7] chore: revert changes --- app/src/main/res/values/strings.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 86ddf85f686..989943f026a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -284,6 +284,8 @@ https://support.wire.com/hc/articles/360002855557 https://support.wire.com/hc/articles/360002855817 https://wire.com/pricing + https://teams.wire.com/login + https://wire.com/en/enterprise Vault Archive From b42349a79bccc900596e647799bb0613491e3754 Mon Sep 17 00:00:00 2001 From: ohassine Date: Fri, 3 Jan 2025 18:41:58 +0100 Subject: [PATCH 6/7] chore: cleanup --- .../kotlin/com/wire/android/di/accountScoped/UserModule.kt | 5 ----- .../ui/userprofile/teammigration/TeamMigrationViewModel.kt | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) 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 2c8c7ac115c..9c96707a661 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 @@ -192,11 +192,6 @@ class UserModule { fun provideGetSelfUseCase(userScope: UserScope): GetSelfUserUseCase = userScope.getSelfUser - @ViewModelScoped - @Provides - fun provideGetTeamUrlUseCase(userScope: UserScope): GetTeamUrlUseCase = - userScope.getTeamUrl - @ViewModelScoped @Provides fun provideGetAvatarAssetUseCase(userScope: UserScope): GetAvatarAssetUseCase = 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 1c1a508c577..d58b88d1bef 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 @@ -38,7 +38,7 @@ class TeamMigrationViewModel @Inject constructor( private val anonymousAnalyticsManager: AnonymousAnalyticsManager, private val migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase, private val getSelfUser: GetSelfUserUseCase, - private val getTeamUrl: GetTeamUrlUseCase, + private val getTeamUrl: GetTeamUrlUseCase ) : ViewModel() { var teamMigrationState by mutableStateOf(TeamMigrationState()) From 92c1660ec71301540e0fdcc0b38c9af24c03d259 Mon Sep 17 00:00:00 2001 From: ohassine Date: Fri, 3 Jan 2025 18:48:17 +0100 Subject: [PATCH 7/7] chore: cleanup --- .../main/kotlin/com/wire/android/di/accountScoped/UserModule.kt | 1 - 1 file changed, 1 deletion(-) 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 9c96707a661..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 @@ -37,7 +37,6 @@ import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersona import com.wire.kalium.logic.feature.publicuser.GetAllContactsUseCase import com.wire.kalium.logic.feature.publicuser.GetKnownUserUseCase import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase -import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase import com.wire.kalium.logic.feature.user.DeleteAccountUseCase import com.wire.kalium.logic.feature.user.GetSelfUserUseCase import com.wire.kalium.logic.feature.user.GetUserInfoUseCase