Merge pull request #6065 from vector-im/feature/adm/matrix-org-ordering

FTUE - Only override sign up steps for `matrix.org`
This commit is contained in:
Adam Brown 2022-05-23 21:24:48 +01:00 committed by GitHub
commit a59b8bf50c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 13 deletions

1
changelog.d/5783.wip Normal file
View File

@ -0,0 +1 @@
FTUE - Overrides sign up flow ordering for matrix.org only

View File

@ -43,6 +43,7 @@ import im.vector.app.features.login.ReAuthHelper
import im.vector.app.features.login.ServerType
import im.vector.app.features.login.SignMode
import im.vector.app.features.onboarding.StartAuthenticationFlowUseCase.StartAuthenticationResult
import im.vector.app.features.onboarding.ftueauth.MatrixOrgRegistrationStagesComparator
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
@ -293,9 +294,19 @@ class OnboardingViewModel @AssistedInject constructor(
}
private fun emitFlowResultViewEvent(flowResult: FlowResult) {
_viewEvents.post(OnboardingViewEvents.RegistrationFlowResult(flowResult, isRegistrationStarted))
withState { state ->
val orderedResult = when {
state.hasSelectedMatrixOrg() && vectorFeatures.isOnboardingCombinedRegisterEnabled() -> flowResult.copy(
missingStages = flowResult.missingStages.sortedWith(MatrixOrgRegistrationStagesComparator())
)
else -> flowResult
}
_viewEvents.post(OnboardingViewEvents.RegistrationFlowResult(orderedResult, isRegistrationStarted))
}
}
private fun OnboardingViewState.hasSelectedMatrixOrg() = selectedHomeserver.userFacingUrl == matrixOrgUrl
private fun handleRegisterWith(action: OnboardingAction.Register) {
reAuthHelper.data = action.password
handleRegisterAction(

View File

@ -54,7 +54,6 @@ import im.vector.app.features.onboarding.OnboardingViewState
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthLegacyStyleTermsFragment
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragment
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsLegacyStyleFragmentArgument
import org.matrix.android.sdk.api.auth.registration.FlowResult
import org.matrix.android.sdk.api.auth.registration.Stage
import org.matrix.android.sdk.api.auth.toLocalizedLoginTerms
import org.matrix.android.sdk.api.extensions.tryOrNull
@ -235,17 +234,12 @@ class FtueAuthVariant(
private fun onRegistrationFlow(viewEvents: OnboardingViewEvents.RegistrationFlowResult) {
when {
registrationShouldFallback(viewEvents) -> displayFallbackWebDialog()
viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult.orderedStages())
viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult.missingStages)
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> openStartCombinedRegister()
else -> openAuthLoginFragmentWithTag(FRAGMENT_REGISTRATION_STAGE_TAG)
}
}
private fun FlowResult.orderedStages() = when {
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> missingStages.sortedWith(FtueMissingRegistrationStagesComparator())
else -> missingStages
}
private fun openStartCombinedRegister() {
addRegistrationStageFragmentToBackstack(FtueAuthCombinedRegisterFragment::class.java)
}

View File

@ -18,10 +18,10 @@ package im.vector.app.features.onboarding.ftueauth
import org.matrix.android.sdk.api.auth.registration.Stage
class FtueMissingRegistrationStagesComparator : Comparator<Stage> {
class MatrixOrgRegistrationStagesComparator : Comparator<Stage> {
override fun compare(a: Stage?, b: Stage?): Int {
return (a?.toPriority() ?: 0) - (b?.toPriority() ?: 0)
override fun compare(a: Stage, b: Stage): Int {
return a.toPriority().compareTo(b.toPriority())
}
private fun Stage.toPriority() = when (this) {

View File

@ -25,7 +25,7 @@ import im.vector.app.test.fixtures.anOtherStage
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
class FtueMissingRegistrationStagesComparatorTest {
class MatrixOrgRegistrationStagesComparatorTest {
@Test
fun `when ordering stages, then prioritizes email`() {
@ -38,7 +38,7 @@ class FtueMissingRegistrationStagesComparatorTest {
aTermsStage()
)
val result = input.sortedWith(FtueMissingRegistrationStagesComparator())
val result = input.sortedWith(MatrixOrgRegistrationStagesComparator())
result shouldBeEqualTo listOf(
anEmailStage(),