formatting

This commit is contained in:
Adam Brown 2022-06-09 17:39:15 +01:00
parent befcfe8c5b
commit 6681d4fe17
4 changed files with 49 additions and 49 deletions

View file

@ -147,18 +147,18 @@ class OnboardingViewModel @AssistedInject constructor(
is OnboardingAction.WebLoginSuccess -> handleWebLoginSuccess(action) is OnboardingAction.WebLoginSuccess -> handleWebLoginSuccess(action)
is OnboardingAction.ResetPassword -> handleResetPassword(action) is OnboardingAction.ResetPassword -> handleResetPassword(action)
is OnboardingAction.ResetPasswordMailConfirmed -> handleResetPasswordMailConfirmed() is OnboardingAction.ResetPasswordMailConfirmed -> handleResetPasswordMailConfirmed()
is OnboardingAction.PostRegisterAction -> handleRegisterAction(action.registerAction) is OnboardingAction.PostRegisterAction -> handleRegisterAction(action.registerAction)
is OnboardingAction.ResetAction -> handleResetAction(action) is OnboardingAction.ResetAction -> handleResetAction(action)
is OnboardingAction.UserAcceptCertificate -> handleUserAcceptCertificate(action) is OnboardingAction.UserAcceptCertificate -> handleUserAcceptCertificate(action)
OnboardingAction.ClearHomeServerHistory -> handleClearHomeServerHistory() OnboardingAction.ClearHomeServerHistory -> handleClearHomeServerHistory()
is OnboardingAction.UpdateDisplayName -> updateDisplayName(action.displayName) is OnboardingAction.UpdateDisplayName -> updateDisplayName(action.displayName)
OnboardingAction.UpdateDisplayNameSkipped -> handleDisplayNameStepComplete() OnboardingAction.UpdateDisplayNameSkipped -> handleDisplayNameStepComplete()
OnboardingAction.UpdateProfilePictureSkipped -> completePersonalization() OnboardingAction.UpdateProfilePictureSkipped -> completePersonalization()
OnboardingAction.PersonalizeProfile -> handlePersonalizeProfile() OnboardingAction.PersonalizeProfile -> handlePersonalizeProfile()
is OnboardingAction.ProfilePictureSelected -> handleProfilePictureSelected(action) is OnboardingAction.ProfilePictureSelected -> handleProfilePictureSelected(action)
OnboardingAction.SaveSelectedProfilePicture -> updateProfilePicture() OnboardingAction.SaveSelectedProfilePicture -> updateProfilePicture()
is OnboardingAction.PostViewEvent -> _viewEvents.post(action.viewEvent) is OnboardingAction.PostViewEvent -> _viewEvents.post(action.viewEvent)
OnboardingAction.StopEmailValidationCheck -> cancelWaitForEmailValidation() OnboardingAction.StopEmailValidationCheck -> cancelWaitForEmailValidation()
} }
} }
@ -276,10 +276,10 @@ class OnboardingViewModel @AssistedInject constructor(
runCatching { registrationActionHandler.processAction(awaitState().selectedHomeserver, action) }.fold( runCatching { registrationActionHandler.processAction(awaitState().selectedHomeserver, action) }.fold(
onSuccess = { onSuccess = {
when (it) { when (it) {
RegistrationActionHandler.Result.Ignored -> { RegistrationActionHandler.Result.Ignored -> {
// do nothing // do nothing
} }
is RegistrationActionHandler.Result.NextStage -> { is RegistrationActionHandler.Result.NextStage -> {
overrideNextStage?.invoke() ?: _viewEvents.post(OnboardingViewEvents.DisplayRegistrationStage(it.stage)) overrideNextStage?.invoke() ?: _viewEvents.post(OnboardingViewEvents.DisplayRegistrationStage(it.stage))
} }
is RegistrationActionHandler.Result.RegistrationComplete -> onSessionCreated( is RegistrationActionHandler.Result.RegistrationComplete -> onSessionCreated(
@ -287,11 +287,11 @@ class OnboardingViewModel @AssistedInject constructor(
authenticationDescription = awaitState().selectedAuthenticationState.description authenticationDescription = awaitState().selectedAuthenticationState.description
?: AuthenticationDescription.Register(AuthenticationDescription.AuthenticationType.Other) ?: AuthenticationDescription.Register(AuthenticationDescription.AuthenticationType.Other)
) )
RegistrationActionHandler.Result.StartRegistration -> _viewEvents.post(OnboardingViewEvents.DisplayStartRegistration) RegistrationActionHandler.Result.StartRegistration -> _viewEvents.post(OnboardingViewEvents.DisplayStartRegistration)
RegistrationActionHandler.Result.UnsupportedStage -> _viewEvents.post(OnboardingViewEvents.DisplayRegistrationFallback) RegistrationActionHandler.Result.UnsupportedStage -> _viewEvents.post(OnboardingViewEvents.DisplayRegistrationFallback)
is RegistrationActionHandler.Result.SendEmailSuccess -> _viewEvents.post(OnboardingViewEvents.OnSendEmailSuccess(it.email)) is RegistrationActionHandler.Result.SendEmailSuccess -> _viewEvents.post(OnboardingViewEvents.OnSendEmailSuccess(it.email))
is RegistrationActionHandler.Result.Error -> _viewEvents.post(OnboardingViewEvents.Failure(it.cause)) is RegistrationActionHandler.Result.Error -> _viewEvents.post(OnboardingViewEvents.Failure(it.cause))
RegistrationActionHandler.Result.MissingNextStage -> { RegistrationActionHandler.Result.MissingNextStage -> {
_viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("No next registration stage found"))) _viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("No next registration stage found")))
} }
} }
@ -368,8 +368,8 @@ class OnboardingViewModel @AssistedInject constructor(
private fun handleUpdateSignMode(action: OnboardingAction.UpdateSignMode) { private fun handleUpdateSignMode(action: OnboardingAction.UpdateSignMode) {
updateSignMode(action.signMode) updateSignMode(action.signMode)
when (action.signMode) { when (action.signMode) {
SignMode.SignUp -> handleRegisterAction(RegisterAction.StartRegistration) SignMode.SignUp -> handleRegisterAction(RegisterAction.StartRegistration)
SignMode.SignIn -> startAuthenticationFlow() SignMode.SignIn -> startAuthenticationFlow()
SignMode.SignInWithMatrixId -> _viewEvents.post(OnboardingViewEvents.OnSignModeSelected(SignMode.SignInWithMatrixId)) SignMode.SignInWithMatrixId -> _viewEvents.post(OnboardingViewEvents.OnSignModeSelected(SignMode.SignInWithMatrixId))
SignMode.Unknown -> Unit SignMode.Unknown -> Unit
} }

View file

@ -44,11 +44,11 @@ class RegistrationActionHandler @Inject constructor(
val result = registrationWizardActionDelegate.executeAction(action) val result = registrationWizardActionDelegate.executeAction(action)
return when { return when {
action.ignoresResult() -> Result.Ignored action.ignoresResult() -> Result.Ignored
else -> when (result) { else -> when (result) {
is RegistrationResult.Complete -> Result.RegistrationComplete(result.session) is RegistrationResult.Complete -> Result.RegistrationComplete(result.session)
is RegistrationResult.NextStep -> processFlowResult(result, state) is RegistrationResult.NextStep -> processFlowResult(result, state)
is RegistrationResult.SendEmailSuccess -> Result.SendEmailSuccess(result.email) is RegistrationResult.SendEmailSuccess -> Result.SendEmailSuccess(result.email)
is RegistrationResult.Error -> Result.Error(result.cause) is RegistrationResult.Error -> Result.Error(result.cause)
} }
} }
} }
@ -66,9 +66,9 @@ class RegistrationActionHandler @Inject constructor(
private suspend fun handleNextStep(state: SelectedHomeserverState, flowResult: FlowResult): Result { private suspend fun handleNextStep(state: SelectedHomeserverState, flowResult: FlowResult): Result {
return when { return when {
flowResult.registrationShouldFallback() -> Result.UnsupportedStage flowResult.registrationShouldFallback() -> Result.UnsupportedStage
authenticationService.isRegistrationStarted() -> findNextStage(state, flowResult) authenticationService.isRegistrationStarted() -> findNextStage(state, flowResult)
else -> Result.StartRegistration else -> Result.StartRegistration
} }
} }
@ -77,7 +77,7 @@ class RegistrationActionHandler @Inject constructor(
state.hasSelectedMatrixOrg() && vectorFeatures.isOnboardingCombinedRegisterEnabled() -> flowResult.copy( state.hasSelectedMatrixOrg() && vectorFeatures.isOnboardingCombinedRegisterEnabled() -> flowResult.copy(
missingStages = flowResult.missingStages.sortedWith(MatrixOrgRegistrationStagesComparator()) missingStages = flowResult.missingStages.sortedWith(MatrixOrgRegistrationStagesComparator())
) )
else -> flowResult else -> flowResult
} }
return orderedResult.findNextRegistrationStage() return orderedResult.findNextRegistrationStage()
?.let { Result.NextStage(it) } ?.let { Result.NextStage(it) }

View file

@ -36,15 +36,15 @@ class RegistrationWizardActionDelegate @Inject constructor(
suspend fun executeAction(action: RegisterAction): RegistrationResult { suspend fun executeAction(action: RegisterAction): RegistrationResult {
return when (action) { return when (action) {
RegisterAction.StartRegistration -> resultOf { registrationWizard.getRegistrationFlow() } RegisterAction.StartRegistration -> resultOf { registrationWizard.getRegistrationFlow() }
is RegisterAction.CaptchaDone -> resultOf { registrationWizard.performReCaptcha(action.captchaResponse) } is RegisterAction.CaptchaDone -> resultOf { registrationWizard.performReCaptcha(action.captchaResponse) }
is RegisterAction.AcceptTerms -> resultOf { registrationWizard.acceptTerms() } is RegisterAction.AcceptTerms -> resultOf { registrationWizard.acceptTerms() }
is RegisterAction.RegisterDummy -> resultOf { registrationWizard.dummy() } is RegisterAction.RegisterDummy -> resultOf { registrationWizard.dummy() }
is RegisterAction.AddThreePid -> handleAddThreePid(registrationWizard, action) is RegisterAction.AddThreePid -> handleAddThreePid(registrationWizard, action)
is RegisterAction.SendAgainThreePid -> resultOf { registrationWizard.sendAgainThreePid() } is RegisterAction.SendAgainThreePid -> resultOf { registrationWizard.sendAgainThreePid() }
is RegisterAction.ValidateThreePid -> resultOf { registrationWizard.handleValidateThreePid(action.code) } is RegisterAction.ValidateThreePid -> resultOf { registrationWizard.handleValidateThreePid(action.code) }
is RegisterAction.CheckIfEmailHasBeenValidated -> handleCheckIfEmailIsValidated(registrationWizard, action.delayMillis) is RegisterAction.CheckIfEmailHasBeenValidated -> handleCheckIfEmailIsValidated(registrationWizard, action.delayMillis)
is RegisterAction.CreateAccount -> resultOf { is RegisterAction.CreateAccount -> resultOf {
registrationWizard.createAccount( registrationWizard.createAccount(
action.username, action.username,
action.password, action.password,
@ -60,7 +60,7 @@ class RegistrationWizardActionDelegate @Inject constructor(
onFailure = { onFailure = {
when { when {
action.threePid is RegisterThreePid.Email && it.is401() -> RegistrationResult.SendEmailSuccess(action.threePid.email) action.threePid is RegisterThreePid.Email && it.is401() -> RegistrationResult.SendEmailSuccess(action.threePid.email)
else -> RegistrationResult.Error(it) else -> RegistrationResult.Error(it)
} }
} }
) )
@ -72,7 +72,7 @@ class RegistrationWizardActionDelegate @Inject constructor(
onFailure = { onFailure = {
when { when {
it.is401() -> null // recursively continue to check with a delay it.is401() -> null // recursively continue to check with a delay
else -> RegistrationResult.Error(it) else -> RegistrationResult.Error(it)
} }
} }
) ?: handleCheckIfEmailIsValidated(registrationWizard, 10_000) ) ?: handleCheckIfEmailIsValidated(registrationWizard, 10_000)
@ -88,7 +88,7 @@ private inline fun resultOf(block: () -> MatrixRegistrationResult): Registration
private fun MatrixRegistrationResult.toRegistrationResult() = when (this) { private fun MatrixRegistrationResult.toRegistrationResult() = when (this) {
is FlowResponse -> RegistrationResult.NextStep(flowResult) is FlowResponse -> RegistrationResult.NextStep(flowResult)
is Success -> RegistrationResult.Complete(session) is Success -> RegistrationResult.Complete(session)
} }
sealed interface RegistrationResult { sealed interface RegistrationResult {
@ -114,10 +114,10 @@ sealed interface RegisterAction {
fun RegisterAction.ignoresResult() = when (this) { fun RegisterAction.ignoresResult() = when (this) {
is RegisterAction.SendAgainThreePid -> true is RegisterAction.SendAgainThreePid -> true
else -> false else -> false
} }
fun RegisterAction.hasLoadingState() = when (this) { fun RegisterAction.hasLoadingState() = when (this) {
is RegisterAction.CheckIfEmailHasBeenValidated -> false is RegisterAction.CheckIfEmailHasBeenValidated -> false
else -> true else -> true
} }

View file

@ -128,7 +128,7 @@ class FtueAuthVariant(
private fun handleOnboardingViewEvents(viewEvents: OnboardingViewEvents) { private fun handleOnboardingViewEvents(viewEvents: OnboardingViewEvents) {
when (viewEvents) { when (viewEvents) {
is OnboardingViewEvents.OutdatedHomeserver -> { is OnboardingViewEvents.OutdatedHomeserver -> {
MaterialAlertDialogBuilder(activity) MaterialAlertDialogBuilder(activity)
.setTitle(R.string.login_error_outdated_homeserver_title) .setTitle(R.string.login_error_outdated_homeserver_title)
.setMessage(R.string.login_error_outdated_homeserver_warning_content) .setMessage(R.string.login_error_outdated_homeserver_warning_content)
@ -223,14 +223,14 @@ class FtueAuthVariant(
option = commonOption option = commonOption
) )
} }
OnboardingViewEvents.OnHomeserverEdited -> activity.popBackstack() OnboardingViewEvents.OnHomeserverEdited -> activity.popBackstack()
OnboardingViewEvents.OpenCombinedLogin -> onStartCombinedLogin() OnboardingViewEvents.OpenCombinedLogin -> onStartCombinedLogin()
is OnboardingViewEvents.DeeplinkAuthenticationFailure -> onDeeplinkedHomeserverUnavailable(viewEvents) is OnboardingViewEvents.DeeplinkAuthenticationFailure -> onDeeplinkedHomeserverUnavailable(viewEvents)
OnboardingViewEvents.DisplayRegistrationFallback -> displayFallbackWebDialog() OnboardingViewEvents.DisplayRegistrationFallback -> displayFallbackWebDialog()
is OnboardingViewEvents.DisplayRegistrationStage -> doStage(viewEvents.stage) is OnboardingViewEvents.DisplayRegistrationStage -> doStage(viewEvents.stage)
OnboardingViewEvents.DisplayStartRegistration -> when { OnboardingViewEvents.DisplayStartRegistration -> when {
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> openStartCombinedRegister() vectorFeatures.isOnboardingCombinedRegisterEnabled() -> openStartCombinedRegister()
else -> openAuthLoginFragmentWithTag(FRAGMENT_REGISTRATION_STAGE_TAG) else -> openAuthLoginFragmentWithTag(FRAGMENT_REGISTRATION_STAGE_TAG)
} }
} }
} }