File tree 5 files changed +19
-13
lines changed
main/java/im/vector/app/features/onboarding
test/java/im/vector/app/features/onboarding/ftueauth
5 files changed +19
-13
lines changed Original file line number Diff line number Diff line change
1
+ FTUE - Overrides sign up flow ordering for matrix.org only
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ import im.vector.app.features.login.ReAuthHelper
43
43
import im.vector.app.features.login.ServerType
44
44
import im.vector.app.features.login.SignMode
45
45
import im.vector.app.features.onboarding.StartAuthenticationFlowUseCase.StartAuthenticationResult
46
+ import im.vector.app.features.onboarding.ftueauth.MatrixOrgRegistrationStagesComparator
46
47
import kotlinx.coroutines.Job
47
48
import kotlinx.coroutines.flow.firstOrNull
48
49
import kotlinx.coroutines.launch
@@ -293,9 +294,19 @@ class OnboardingViewModel @AssistedInject constructor(
293
294
}
294
295
295
296
private fun emitFlowResultViewEvent (flowResult : FlowResult ) {
296
- _viewEvents .post(OnboardingViewEvents .RegistrationFlowResult (flowResult, isRegistrationStarted))
297
+ withState { state ->
298
+ val orderedResult = when {
299
+ state.hasSelectedMatrixOrg() && vectorFeatures.isOnboardingCombinedRegisterEnabled() -> flowResult.copy(
300
+ missingStages = flowResult.missingStages.sortedWith(MatrixOrgRegistrationStagesComparator ())
301
+ )
302
+ else -> flowResult
303
+ }
304
+ _viewEvents .post(OnboardingViewEvents .RegistrationFlowResult (orderedResult, isRegistrationStarted))
305
+ }
297
306
}
298
307
308
+ private fun OnboardingViewState.hasSelectedMatrixOrg () = selectedHomeserver.userFacingUrl == matrixOrgUrl
309
+
299
310
private fun handleRegisterWith (action : OnboardingAction .Register ) {
300
311
reAuthHelper.data = action.password
301
312
handleRegisterAction(
Original file line number Diff line number Diff line change @@ -54,7 +54,6 @@ import im.vector.app.features.onboarding.OnboardingViewState
54
54
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthLegacyStyleTermsFragment
55
55
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragment
56
56
import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsLegacyStyleFragmentArgument
57
- import org.matrix.android.sdk.api.auth.registration.FlowResult
58
57
import org.matrix.android.sdk.api.auth.registration.Stage
59
58
import org.matrix.android.sdk.api.auth.toLocalizedLoginTerms
60
59
import org.matrix.android.sdk.api.extensions.tryOrNull
@@ -235,17 +234,12 @@ class FtueAuthVariant(
235
234
private fun onRegistrationFlow (viewEvents : OnboardingViewEvents .RegistrationFlowResult ) {
236
235
when {
237
236
registrationShouldFallback(viewEvents) -> displayFallbackWebDialog()
238
- viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult.orderedStages() )
237
+ viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult.missingStages )
239
238
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> openStartCombinedRegister()
240
239
else -> openAuthLoginFragmentWithTag(FRAGMENT_REGISTRATION_STAGE_TAG )
241
240
}
242
241
}
243
242
244
- private fun FlowResult.orderedStages () = when {
245
- vectorFeatures.isOnboardingCombinedRegisterEnabled() -> missingStages.sortedWith(FtueMissingRegistrationStagesComparator ())
246
- else -> missingStages
247
- }
248
-
249
243
private fun openStartCombinedRegister () {
250
244
addRegistrationStageFragmentToBackstack(FtueAuthCombinedRegisterFragment ::class .java)
251
245
}
Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ package im.vector.app.features.onboarding.ftueauth
18
18
19
19
import org.matrix.android.sdk.api.auth.registration.Stage
20
20
21
- class FtueMissingRegistrationStagesComparator : Comparator <Stage > {
21
+ class MatrixOrgRegistrationStagesComparator : Comparator <Stage > {
22
22
23
- override fun compare (a : Stage ? , b : Stage ? ): Int {
24
- return (a? .toPriority() ? : 0 ) - (b? .toPriority() ? : 0 )
23
+ override fun compare (a : Stage , b : Stage ): Int {
24
+ return a .toPriority().compareTo(b .toPriority())
25
25
}
26
26
27
27
private fun Stage.toPriority () = when (this ) {
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import im.vector.app.test.fixtures.anOtherStage
25
25
import org.amshove.kluent.shouldBeEqualTo
26
26
import org.junit.Test
27
27
28
- class FtueMissingRegistrationStagesComparatorTest {
28
+ class MatrixOrgRegistrationStagesComparatorTest {
29
29
30
30
@Test
31
31
fun `when ordering stages, then prioritizes email` () {
@@ -38,7 +38,7 @@ class FtueMissingRegistrationStagesComparatorTest {
38
38
aTermsStage()
39
39
)
40
40
41
- val result = input.sortedWith(FtueMissingRegistrationStagesComparator ())
41
+ val result = input.sortedWith(MatrixOrgRegistrationStagesComparator ())
42
42
43
43
result shouldBeEqualTo listOf (
44
44
anEmailStage(),
You can’t perform that action at this time.
0 commit comments