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/di/accountScoped/UserModule.kt b/app/src/main/kotlin/com/wire/android/di/accountScoped/UserModule.kt index 2c8c7ac115c..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 @@ -192,11 +191,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/self/SelfUserProfileScreen.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/self/SelfUserProfileScreen.kt index 60d081bf260..c562b1ba5dc 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 @@ -120,6 +120,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 2820cc43ae5..d3e812b466d 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 @@ -112,7 +112,6 @@ class SelfUserProfileViewModel @Inject constructor( init { viewModelScope.launch { fetchSelfUser() - checkIfUserAbleToMigrateToTeamAccount() observeEstablishedCall() fetchIsReadOnlyAccount() observeLegalHoldStatus() @@ -120,9 +119,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 818a70b9b27..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 @@ -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 6f271514800..153151ac9a1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -284,7 +284,6 @@ https://support.wire.com/hc/articles/360002855557 https://support.wire.com/hc/articles/360002855817 https://wire.com/pricing - https://teams.wire.com/ https://teams.wire.com/login https://wire.com/en/enterprise 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 ef00ce0c20c..fc30d21f0a0 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 @@ -31,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 @@ -267,13 +270,23 @@ class TeamMigrationViewModelTest { @MockK lateinit var migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase + @MockK + lateinit var getSelfUser: GetSelfUserUseCase + + @MockK + lateinit var getTeamUrl: GetTeamUrlUseCase + init { MockKAnnotations.init(this, relaxUnitFun = true) + coEvery { getSelfUser() } returns flowOf() + coEvery { getTeamUrl() } returns "TeamUrl" } fun arrange() = this to TeamMigrationViewModel( anonymousAnalyticsManager = anonymousAnalyticsManager, migrateFromPersonalToTeam = migrateFromPersonalToTeam, + getSelfUser = getSelfUser, + getTeamUrl = getTeamUrl ).also { viewModel -> viewModel.teamMigrationState.teamNameTextState.setTextAndPlaceCursorAtEnd(TEAM_NAME) }