diff --git a/vector/src/main/java/im/vector/app/features/login/LoginFragment.kt b/vector/src/main/java/im/vector/app/features/login/LoginFragment.kt index e8c0b25027..f575aed3f8 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginFragment.kt @@ -37,6 +37,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.api.failure.isInvalidPassword @@ -202,11 +203,11 @@ class LoginFragment @Inject constructor() : AbstractSSOLoginFragment?, mode: SocialLoginButtonsView.Mode, listener: (String?) -> Unit) { +fun SocialLoginButtonsView.render(ssoProviders: List?, mode: SocialLoginButtonsView.Mode, listener: (SsoIdentityProvider?) -> Unit) { this.mode = mode this.ssoIdentityProviders = ssoProviders?.sorted() this.listener = SocialLoginButtonsView.InteractionListener { listener(it) } diff --git a/vector/src/main/java/im/vector/app/features/login2/LoginFragmentSignupUsername2.kt b/vector/src/main/java/im/vector/app/features/login2/LoginFragmentSignupUsername2.kt index f9917a4c31..a7c4b25344 100644 --- a/vector/src/main/java/im/vector/app/features/login2/LoginFragmentSignupUsername2.kt +++ b/vector/src/main/java/im/vector/app/features/login2/LoginFragmentSignupUsername2.kt @@ -35,6 +35,7 @@ import im.vector.app.features.login.SocialLoginButtonsView import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider import reactivecircus.flowbinding.android.widget.textChanges import javax.inject.Inject @@ -96,11 +97,11 @@ class LoginFragmentSignupUsername2 @Inject constructor() : AbstractSSOLoginFragm views.loginSocialLoginContainer.isVisible = true views.loginSocialLoginButtons.ssoIdentityProviders = state.loginMode.ssoIdentityProviders?.sorted() views.loginSocialLoginButtons.listener = object : SocialLoginButtonsView.InteractionListener { - override fun onProviderSelected(id: String?) { + override fun onProviderSelected(provider: SsoIdentityProvider?) { loginViewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = state.deviceId, - providerId = id + providerId = provider?.id ) ?.let { openInCustomTab(it) } } diff --git a/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt b/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt index 064889876b..cc143b9255 100644 --- a/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt +++ b/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt @@ -37,6 +37,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.api.failure.isInvalidPassword @@ -123,11 +124,11 @@ class LoginFragmentToAny2 @Inject constructor() : AbstractSSOLoginFragment2 AuthenticationType.Google + SsoIdentityProvider.BRAND_GITHUB -> AuthenticationType.Github + SsoIdentityProvider.BRAND_APPLE -> AuthenticationType.Apple + SsoIdentityProvider.BRAND_FACEBOOK -> AuthenticationType.Facebook + SsoIdentityProvider.BRAND_GITLAB -> AuthenticationType.Gitlab + SsoIdentityProvider.BRAND_TWITTER -> AuthenticationType.SSO + null -> AuthenticationType.SSO + else -> AuthenticationType.SSO +} 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 b1fbf45f2b..523b89b4f9 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 @@ -255,7 +255,7 @@ class OnboardingViewModel @AssistedInject constructor( currentJob = viewModelScope.launch { try { val result = safeLoginWizard.loginWithToken(action.loginToken) - onSessionCreated(result, isAccountCreated = false) + onSessionCreated(result, authenticationDescription = AuthenticationDescription.Login) } catch (failure: Throwable) { setState { copy(isLoading = false) } _viewEvents.post(OnboardingViewEvents.Failure(failure)) @@ -289,7 +289,12 @@ class OnboardingViewModel @AssistedInject constructor( // do nothing } else -> when (it) { - is RegistrationResult.Complete -> onSessionCreated(it.session, isAccountCreated = true) + is RegistrationResult.Complete -> onSessionCreated( + it.session, + authenticationDescription = AuthenticationDescription.AccountCreated( + AuthenticationDescription.AuthenticationType.Password + ) + ) is RegistrationResult.NextStep -> onFlowResponse(it.flowResult, onNextRegistrationStepAction) is RegistrationResult.SendEmailSuccess -> _viewEvents.post(OnboardingViewEvents.OnSendEmailSuccess(it.email)) is RegistrationResult.Error -> _viewEvents.post(OnboardingViewEvents.Failure(it.cause)) @@ -499,7 +504,7 @@ class OnboardingViewModel @AssistedInject constructor( setState { copy(isLoading = true) } currentJob = viewModelScope.launch { directLoginUseCase.execute(action, homeServerConnectionConfig).fold( - onSuccess = { onSessionCreated(it, isAccountCreated = false) }, + onSuccess = { onSessionCreated(it, authenticationDescription = AuthenticationDescription.Login) }, onFailure = { setState { copy(isLoading = false) } _viewEvents.post(OnboardingViewEvents.Failure(it)) @@ -524,7 +529,7 @@ class OnboardingViewModel @AssistedInject constructor( action.initialDeviceName ) reAuthHelper.data = action.password - onSessionCreated(result, isAccountCreated = false) + onSessionCreated(result, authenticationDescription = AuthenticationDescription.Login) } catch (failure: Throwable) { setState { copy(isLoading = false) } _viewEvents.post(OnboardingViewEvents.Failure(failure)) @@ -553,7 +558,7 @@ class OnboardingViewModel @AssistedInject constructor( internalRegisterAction(RegisterAction.RegisterDummy, onNextRegistrationStepAction) } - private suspend fun onSessionCreated(session: Session, isAccountCreated: Boolean) { + private suspend fun onSessionCreated(session: Session, authenticationDescription: AuthenticationDescription) { val state = awaitState() state.useCase?.let { useCase -> session.vectorStore(applicationContext).setUseCase(useCase) @@ -564,15 +569,15 @@ class OnboardingViewModel @AssistedInject constructor( authenticationService.reset() session.configureAndStart(applicationContext) - when (isAccountCreated) { - true -> { + when (authenticationDescription) { + is AuthenticationDescription.AccountCreated -> { val personalizationState = createPersonalizationState(session, state) setState { copy(isLoading = false, personalizationState = personalizationState) } _viewEvents.post(OnboardingViewEvents.OnAccountCreated) } - false -> { + AuthenticationDescription.Login -> { setState { copy(isLoading = false) } _viewEvents.post(OnboardingViewEvents.OnAccountSignedIn) } @@ -603,7 +608,7 @@ class OnboardingViewModel @AssistedInject constructor( currentJob = viewModelScope.launch { try { val result = authenticationService.createSessionFromSso(homeServerConnectionConfigFinal, action.credentials) - onSessionCreated(result, isAccountCreated = false) + onSessionCreated(result, authenticationDescription = AuthenticationDescription.Login) } catch (failure: Throwable) { setState { copy(isLoading = false) } } 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 f27e5502db..4b0f60e6f4 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 @@ -164,11 +164,11 @@ class FtueAuthCombinedRegisterFragment @Inject constructor() : AbstractSSOFtueAu private fun renderSsoProviders(deviceId: String?, ssoProviders: List?) { views.ssoGroup.isVisible = ssoProviders?.isNotEmpty() == true - views.ssoButtons.render(ssoProviders, SocialLoginButtonsView.Mode.MODE_CONTINUE) { id -> + views.ssoButtons.render(ssoProviders, SocialLoginButtonsView.Mode.MODE_CONTINUE) { provider -> viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = deviceId, - providerId = id + providerId = provider?.id )?.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 98d9a24999..9e910481ba 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 @@ -45,6 +45,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider import org.matrix.android.sdk.api.failure.isInvalidPassword import org.matrix.android.sdk.api.failure.isInvalidUsername import org.matrix.android.sdk.api.failure.isLoginEmailUnknown @@ -216,11 +217,11 @@ class FtueAuthLoginFragment @Inject constructor() : AbstractSSOFtueAuthFragment< views.loginSocialLoginContainer.isVisible = true views.loginSocialLoginButtons.ssoIdentityProviders = state.selectedHomeserver.preferredLoginMode.ssoIdentityProviders?.sorted() views.loginSocialLoginButtons.listener = object : SocialLoginButtonsView.InteractionListener { - override fun onProviderSelected(id: String?) { + override fun onProviderSelected(provider: SsoIdentityProvider?) { viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = state.deviceId, - providerId = id + providerId = provider?.id ) ?.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 69fbd3459b..921715a695 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 @@ -34,6 +34,7 @@ import im.vector.app.features.login.SocialLoginButtonsView import im.vector.app.features.login.ssoIdentityProviders import im.vector.app.features.onboarding.OnboardingAction import im.vector.app.features.onboarding.OnboardingViewState +import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider import javax.inject.Inject /** @@ -81,11 +82,11 @@ class FtueAuthSignUpSignInSelectionFragment @Inject constructor() : AbstractSSOF views.loginSignupSigninSignInSocialLoginContainer.isVisible = true views.loginSignupSigninSocialLoginButtons.ssoIdentityProviders = state.selectedHomeserver.preferredLoginMode.ssoIdentityProviders()?.sorted() views.loginSignupSigninSocialLoginButtons.listener = object : SocialLoginButtonsView.InteractionListener { - override fun onProviderSelected(id: String?) { + override fun onProviderSelected(provider: SsoIdentityProvider?) { viewModel.getSsoUrl( redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL, deviceId = state.deviceId, - providerId = id + providerId = provider?.id ) ?.let { openInCustomTab(it) } }