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 060d2d7a6c2..b0790543e47 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -274,7 +274,6 @@ https://support.wire.com/hc/articles/360002855557 https://support.wire.com/hc/articles/360002855817 https://wire.com/pricing - https://teams.wire.com/ Vault Archive 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..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 @@ -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 @@ -251,13 +254,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) }