diff --git a/changelog.d/2684.bugfix b/changelog.d/2684.bugfix new file mode 100644 index 0000000000..7d46059936 --- /dev/null +++ b/changelog.d/2684.bugfix @@ -0,0 +1,2 @@ +Correctly handle url of type https://mobile.element.io/?hs_url=…&is_url=… +Skip the choose server screen when such URL are open when Element \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/login/LoginAction.kt b/vector/src/main/java/im/vector/app/features/login/LoginAction.kt index f6e1ccc9bc..70ca49a10e 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginAction.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginAction.kt @@ -23,6 +23,8 @@ import org.matrix.android.sdk.api.auth.registration.RegisterThreePid import org.matrix.android.sdk.internal.network.ssl.Fingerprint sealed class LoginAction : VectorViewModelAction { + data class OnGetStarted(val resetLoginConfig: Boolean) : LoginAction() + data class UpdateServerType(val serverType: ServerType) : LoginAction() data class UpdateHomeServer(val homeServerUrl: String) : LoginAction() data class UpdateSignMode(val signMode: SignMode) : LoginAction() diff --git a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt index f0a1b1f937..a01e02f4e0 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt @@ -103,7 +103,6 @@ open class LoginActivity : VectorBaseActivity(), ToolbarCo // Get config extra val loginConfig = intent.getParcelableExtra(EXTRA_CONFIG) if (isFirstCreation()) { - // TODO Check this loginViewModel.handle(LoginAction.InitWith(loginConfig)) } } diff --git a/vector/src/main/java/im/vector/app/features/login/LoginServerSelectionFragment.kt b/vector/src/main/java/im/vector/app/features/login/LoginServerSelectionFragment.kt index 2d40ea818a..89d8985a81 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginServerSelectionFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginServerSelectionFragment.kt @@ -87,10 +87,5 @@ class LoginServerSelectionFragment @Inject constructor() : AbstractLoginFragment override fun updateWithState(state: LoginViewState) { updateSelectedChoice(state) - - if (state.loginMode != LoginMode.Unknown) { - // LoginFlow for matrix.org has been retrieved - loginViewModel.handle(LoginAction.PostViewEvent(LoginViewEvents.OnLoginFlowRetrieved)) - } } } diff --git a/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt b/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt index d0b4d65b19..ebe82b1163 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt @@ -156,10 +156,5 @@ class LoginServerUrlFormFragment @Inject constructor() : AbstractLoginFragment + loginViewModel.handle(LoginAction.OnGetStarted(true)) + } + .setNegativeButton(R.string.cancel, null) + .show() + } else { + super.onError(throwable) + } + } } diff --git a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt index 28a9fa46d1..ca126570ff 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt @@ -19,7 +19,6 @@ package im.vector.app.features.login import android.content.Context import android.net.Uri import androidx.fragment.app.FragmentActivity -import androidx.lifecycle.viewModelScope import com.airbnb.mvrx.ActivityViewModelContext import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Loading @@ -128,6 +127,7 @@ class LoginViewModel @AssistedInject constructor( override fun handle(action: LoginAction) { when (action) { + is LoginAction.OnGetStarted -> handleOnGetStarted(action) is LoginAction.UpdateServerType -> handleUpdateServerType(action) is LoginAction.UpdateSignMode -> handleUpdateSignMode(action) is LoginAction.InitWith -> handleInitWith(action) @@ -146,6 +146,27 @@ class LoginViewModel @AssistedInject constructor( }.exhaustive } + private fun handleOnGetStarted(action: LoginAction.OnGetStarted) { + if (action.resetLoginConfig) { + loginConfig = null + } + + val configUrl = loginConfig?.homeServerUrl?.takeIf { it.isNotEmpty() } + if (configUrl != null) { + // Use config from uri + val homeServerConnectionConfig = homeServerConnectionConfigFactory.create(configUrl) + if (homeServerConnectionConfig == null) { + // Url is invalid, in this case, just use the regular flow + Timber.w("Url from config url was invalid: $configUrl") + _viewEvents.post(LoginViewEvents.OpenServerSelection) + } else { + getLoginFlow(homeServerConnectionConfig, ServerType.Other) + } + } else { + _viewEvents.post(LoginViewEvents.OpenServerSelection) + } + } + private fun handleUserAcceptCertificate(action: LoginAction.UserAcceptCertificate) { // It happens when we get the login flow, or during direct authentication. // So alter the homeserver config and retrieve again the login flow @@ -744,7 +765,8 @@ class LoginViewModel @AssistedInject constructor( } } - private fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig) { + private fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, + serverTypeOverride: ServerType? = null) { currentHomeServerConnectionConfig = homeServerConnectionConfig currentJob = viewModelScope.launch { @@ -755,7 +777,11 @@ class LoginViewModel @AssistedInject constructor( asyncHomeServerLoginFlowRequest = Loading(), // If user has entered https://matrix.org, ensure that server type is ServerType.MatrixOrg // It is also useful to set the value again in the case of a certificate error on matrix.org - serverType = if (homeServerConnectionConfig.homeServerUri.toString() == matrixOrgUrl) ServerType.MatrixOrg else serverType + serverType = if (homeServerConnectionConfig.homeServerUri.toString() == matrixOrgUrl) { + ServerType.MatrixOrg + } else { + serverTypeOverride ?: serverType + } ) } @@ -788,7 +814,6 @@ class LoginViewModel @AssistedInject constructor( else -> LoginMode.Unsupported } - // FIXME We should post a view event here normally? setState { copy( asyncHomeServerLoginFlowRequest = Uninitialized, @@ -803,6 +828,7 @@ class LoginViewModel @AssistedInject constructor( // Notify the UI _viewEvents.post(LoginViewEvents.OutdatedHomeserver) } + _viewEvents.post(LoginViewEvents.OnLoginFlowRetrieved) } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 274753ee3f..0e8197dbae 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -657,6 +657,8 @@ This URL is not reachable, please check it This is not a valid Matrix server address Cannot reach a homeserver at this URL, please check it + Cannot reach a homeserver at the URL %s. Please check your link or choose a homeserver manually. + Choose homeserver "SSL Error: the peer's identity has not been verified." "SSL Error." Your device is using an outdated TLS security protocol, vulnerable to attack, for your security you will not be able to connect