Avoid long lines

This commit is contained in:
Benoit Marty 2021-02-18 16:14:02 +01:00
parent dea76fd81b
commit b9f5863b53
2 changed files with 46 additions and 52 deletions

View File

@ -759,7 +759,7 @@ class LoginViewModel @AssistedInject constructor(
) )
} }
try { val data = try {
authenticationService.getLoginFlow(homeServerConnectionConfig) authenticationService.getLoginFlow(homeServerConnectionConfig)
} catch (failure: Throwable) { } catch (failure: Throwable) {
_viewEvents.post(LoginViewEvents.Failure(failure)) _viewEvents.post(LoginViewEvents.Failure(failure))
@ -772,39 +772,36 @@ class LoginViewModel @AssistedInject constructor(
} }
null null
} }
?.let { data ->
// Valid Homeserver, add it to the history.
// Note: we add what the user has input, data.homeServerUrl can be different
rememberHomeServer(homeServerConnectionConfig.homeServerUri.toString())
when (data) { if (data is LoginFlowResult.Success) {
is LoginFlowResult.Success -> { // Valid Homeserver, add it to the history.
val loginMode = when { // Note: we add what the user has input, data.homeServerUrl can be different
// SSO login is taken first rememberHomeServer(homeServerConnectionConfig.homeServerUri.toString())
data.supportedLoginTypes.contains(LoginFlowTypes.SSO)
&& data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.SsoAndPassword(data.ssoIdentityProviders)
data.supportedLoginTypes.contains(LoginFlowTypes.SSO) -> LoginMode.Sso(data.ssoIdentityProviders)
data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.Password
else -> LoginMode.Unsupported
}
// FIXME We should post a view event here normally? val loginMode = when {
setState { // SSO login is taken first
copy( data.supportedLoginTypes.contains(LoginFlowTypes.SSO)
asyncHomeServerLoginFlowRequest = Uninitialized, && data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.SsoAndPassword(data.ssoIdentityProviders)
homeServerUrl = data.homeServerUrl, data.supportedLoginTypes.contains(LoginFlowTypes.SSO) -> LoginMode.Sso(data.ssoIdentityProviders)
loginMode = loginMode, data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.Password
loginModeSupportedTypes = data.supportedLoginTypes.toList() else -> LoginMode.Unsupported
) }
}
if ((loginMode == LoginMode.Password && !data.isLoginAndRegistrationSupported) // FIXME We should post a view event here normally?
|| data.isOutdatedHomeserver) { setState {
// Notify the UI copy(
_viewEvents.post(LoginViewEvents.OutdatedHomeserver) asyncHomeServerLoginFlowRequest = Uninitialized,
} homeServerUrl = data.homeServerUrl,
} loginMode = loginMode,
} loginModeSupportedTypes = data.supportedLoginTypes.toList()
} )
}
if ((loginMode == LoginMode.Password && !data.isLoginAndRegistrationSupported)
|| data.isOutdatedHomeserver) {
// Notify the UI
_viewEvents.post(LoginViewEvents.OutdatedHomeserver)
}
}
} }
} }

View File

@ -89,7 +89,7 @@ class SoftLogoutViewModel @AssistedInject constructor(
) )
} }
try { val data = try {
authenticationService.getLoginFlowOfSession(session.sessionId) authenticationService.getLoginFlowOfSession(session.sessionId)
} catch (failure: Throwable) { } catch (failure: Throwable) {
setState { setState {
@ -99,26 +99,23 @@ class SoftLogoutViewModel @AssistedInject constructor(
} }
null null
} }
?.let { data ->
when (data) {
is LoginFlowResult.Success -> {
val loginMode = when {
// SSO login is taken first
data.supportedLoginTypes.contains(LoginFlowTypes.SSO)
&& data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.SsoAndPassword(data.ssoIdentityProviders)
data.supportedLoginTypes.contains(LoginFlowTypes.SSO) -> LoginMode.Sso(data.ssoIdentityProviders)
data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.Password
else -> LoginMode.Unsupported
}
setState { if (data is LoginFlowResult.Success) {
copy( val loginMode = when {
asyncHomeServerLoginFlowRequest = Success(loginMode) // SSO login is taken first
) data.supportedLoginTypes.contains(LoginFlowTypes.SSO)
} && data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.SsoAndPassword(data.ssoIdentityProviders)
} data.supportedLoginTypes.contains(LoginFlowTypes.SSO) -> LoginMode.Sso(data.ssoIdentityProviders)
} data.supportedLoginTypes.contains(LoginFlowTypes.PASSWORD) -> LoginMode.Password
} else -> LoginMode.Unsupported
}
setState {
copy(
asyncHomeServerLoginFlowRequest = Success(loginMode)
)
}
}
} }
} }