Skip to content

Commit

Permalink
Merge branch 'develop' into ci/adjust-s3bucket-configs
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina authored Jan 6, 2025
2 parents 3597ec0 + 73cf82e commit 97473ab
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 17 deletions.
10 changes: 8 additions & 2 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ fun SelfUserProfileScreen(
) {
val legalHoldSubjectDialogState = rememberVisibilityState<Unit>()

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,15 @@ class SelfUserProfileViewModel @Inject constructor(
init {
viewModelScope.launch {
fetchSelfUser()
checkIfUserAbleToMigrateToTeamAccount()
observeEstablishedCall()
fetchIsReadOnlyAccount()
observeLegalHoldStatus()
markCreateTeamNoticeAsRead()
}
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ fun TeamMigrationDoneStepScreen(
) {
val context = LocalContext.current

val teamManagementUrl = stringResource(R.string.url_team_management)
TeamMigrationDoneStepContent(
onBackToWireClicked = {
teamMigrationViewModel.sendPersonalTeamCreationFlowCompletedEvent(
Expand All @@ -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()
)

Expand All @@ -98,6 +100,7 @@ fun TeamMigrationDoneStepScreen(
private fun TeamMigrationDoneStepContent(
onBackToWireClicked: () -> Unit,
onOpenTeamManagementClicked: () -> Unit,
username: String,
teamName: String,
modifier: Modifier = Modifier
) {
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -187,6 +190,6 @@ private fun TeamMigrationDoneStepContent(
@Composable
private fun TeamMigrationDoneStepScreenPreview() {
WireTheme {
TeamMigrationDoneStepContent({}, {}, teamName = "teamName")
TeamMigrationDoneStepContent({}, {}, username = "John", teamName = "teamName")
}
}
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
<string name="url_how_to_add_favorites" translatable="false">https://support.wire.com/hc/articles/360002855557</string>
<string name="url_how_to_add_folders" translatable="false">https://support.wire.com/hc/articles/360002855817</string>
<string name="url_wire_plans" translatable="false">https://wire.com/pricing</string>
<string name="url_team_management" translatable="false">https://teams.wire.com/</string>
<string name="url_team_management_login" translatable="false">https://teams.wire.com/login</string>
<string name="url_wire_enterprise" translatable="false">https://wire.com/en/enterprise</string>
<!-- Navigation -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 97473ab

Please sign in to comment.