From ac89495348c135ea8a80e0dac5b3fc170b28354e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 12 May 2022 17:52:05 +0100 Subject: [PATCH] chaining the current authentication type into the onboarding state --- .../app/features/onboarding/OnboardingViewModel.kt | 9 ++++++--- .../app/features/onboarding/OnboardingViewState.kt | 8 ++++++++ .../onboarding/ftueauth/AbstractSSOFtueAuthFragment.kt | 2 +- .../ftueauth/FtueAuthCombinedRegisterFragment.kt | 2 +- .../onboarding/ftueauth/FtueAuthLoginFragment.kt | 2 +- .../ftueauth/FtueAuthSignUpSignInSelectionFragment.kt | 4 ++-- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt index 523b89b4f9..344a388d7a 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt @@ -54,6 +54,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.HomeServerHistoryService import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig +import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider import org.matrix.android.sdk.api.auth.login.LoginWizard import org.matrix.android.sdk.api.auth.registration.FlowResult import org.matrix.android.sdk.api.auth.registration.RegistrationWizard @@ -292,7 +293,7 @@ class OnboardingViewModel @AssistedInject constructor( is RegistrationResult.Complete -> onSessionCreated( it.session, authenticationDescription = AuthenticationDescription.AccountCreated( - AuthenticationDescription.AuthenticationType.Password + awaitState().selectedAuthenticationState.type ?: AuthenticationDescription.AuthenticationType.Other ) ) is RegistrationResult.NextStep -> onFlowResponse(it.flowResult, onNextRegistrationStepAction) @@ -324,6 +325,7 @@ class OnboardingViewModel @AssistedInject constructor( private fun OnboardingViewState.hasSelectedMatrixOrg() = selectedHomeserver.userFacingUrl == matrixOrgUrl private fun handleRegisterWith(action: AuthenticateAction.Register) { + setState { copy(selectedAuthenticationState = SelectedAuthenticationState(AuthenticationDescription.AuthenticationType.Password)) } reAuthHelper.data = action.password handleRegisterAction( RegisterAction.CreateAccount( @@ -750,8 +752,9 @@ class OnboardingViewModel @AssistedInject constructor( return loginConfig?.homeServerUrl } - fun getSsoUrl(redirectUrl: String, deviceId: String?, providerId: String?): String? { - return authenticationService.getSsoUrl(redirectUrl, deviceId, providerId) + fun getSsoUrl(redirectUrl: String, deviceId: String?, provider: SsoIdentityProvider?): String? { + setState { copy(selectedAuthenticationState = SelectedAuthenticationState(provider.toAuthenticationType())) } + return authenticationService.getSsoUrl(redirectUrl, deviceId, provider?.id) } fun getFallbackUrl(forSignIn: Boolean, deviceId: String?): String? { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt index 442a0a7df1..9b9bf9bf4f 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt @@ -51,6 +51,9 @@ data class OnboardingViewState( @PersistState val selectedHomeserver: SelectedHomeserverState = SelectedHomeserverState(), + @PersistState + val selectedAuthenticationState: SelectedAuthenticationState = SelectedAuthenticationState(), + @PersistState val personalizationState: PersonalizationState = PersonalizationState() ) : MavericksState @@ -80,3 +83,8 @@ data class PersonalizationState( fun supportsPersonalization() = supportsChangingDisplayName || supportsChangingProfilePicture } + +@Parcelize +data class SelectedAuthenticationState( + val type: AuthenticationDescription.AuthenticationType? = null, +) : Parcelable diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractSSOFtueAuthFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractSSOFtueAuthFragment.kt index a032181e4d..3292e37de2 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractSSOFtueAuthFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractSSOFtueAuthFragment.kt @@ -93,7 +93,7 @@ abstract class AbstractSSOFtueAuthFragment : AbstractFtueAuthF viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = state.deviceId, - providerId = null + provider = null ) ?.let { prefetchUrl(it) } } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt index 4b0f60e6f4..494ba6bc7e 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt @@ -168,7 +168,7 @@ class FtueAuthCombinedRegisterFragment @Inject constructor() : AbstractSSOFtueAu viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = deviceId, - providerId = provider?.id + provider = provider )?.let { openInCustomTab(it) } } } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt index 9e910481ba..e3f6c2db76 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt @@ -221,7 +221,7 @@ class FtueAuthLoginFragment @Inject constructor() : AbstractSSOFtueAuthFragment< viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = state.deviceId, - providerId = provider?.id + provider = provider ) ?.let { openInCustomTab(it) } } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSignUpSignInSelectionFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSignUpSignInSelectionFragment.kt index 921715a695..b2307168fd 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSignUpSignInSelectionFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSignUpSignInSelectionFragment.kt @@ -86,7 +86,7 @@ class FtueAuthSignUpSignInSelectionFragment @Inject constructor() : AbstractSSOF viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = state.deviceId, - providerId = provider?.id + provider = provider ) ?.let { openInCustomTab(it) } } @@ -127,7 +127,7 @@ class FtueAuthSignUpSignInSelectionFragment @Inject constructor() : AbstractSSOF viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = state.deviceId, - providerId = null + provider = null ) ?.let { openInCustomTab(it) } } else {