Merge pull request #5692 from element-hq/feature/bma/loginFlow

Improve account provider selection during the login flow
This commit is contained in:
Benoit Marty 2025-11-07 16:48:03 +01:00 committed by GitHub
commit 77bc9b811a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 366 additions and 254 deletions

View file

@ -12,7 +12,6 @@ import org.matrix.rustcomponents.sdk.ClientBuildException
import org.matrix.rustcomponents.sdk.OidcException
fun Throwable.mapAuthenticationException(): AuthenticationException {
val message = this.message ?: "Unknown error"
return when (this) {
is AuthenticationException -> this
is ClientBuildException -> when (this) {
@ -20,7 +19,7 @@ fun Throwable.mapAuthenticationException(): AuthenticationException {
is ClientBuildException.InvalidServerName -> AuthenticationException.InvalidServerName(message)
is ClientBuildException.SlidingSyncVersion -> AuthenticationException.SlidingSyncVersion(message)
is ClientBuildException.Sdk -> AuthenticationException.Generic(message)
is ClientBuildException.ServerUnreachable -> AuthenticationException.Generic(message)
is ClientBuildException.ServerUnreachable -> AuthenticationException.ServerUnreachable(message)
is ClientBuildException.SlidingSync -> AuthenticationException.Generic(message)
is ClientBuildException.WellKnownDeserializationException -> AuthenticationException.Generic(message)
is ClientBuildException.WellKnownLookupFailed -> AuthenticationException.Generic(message)

View file

@ -36,8 +36,6 @@ import io.element.android.libraries.matrix.impl.paths.SessionPathsFactory
import io.element.android.libraries.sessionstorage.api.LoginType
import io.element.android.libraries.sessionstorage.api.SessionStore
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.withContext
import org.matrix.rustcomponents.sdk.Client
import org.matrix.rustcomponents.sdk.ClientBuilder
@ -67,7 +65,6 @@ class RustMatrixAuthenticationService(
// Ideally it would be possible to get the sessionPath from the Client to avoid doing this.
private var sessionPaths: SessionPaths? = null
private var currentClient: Client? = null
private var currentHomeserver = MutableStateFlow<MatrixHomeServerDetails?>(null)
private val newMatrixClientObservers = mutableListOf<(MatrixClient) -> Unit>()
override fun listenToNewMatrixClients(lambda: (MatrixClient) -> Unit) {
@ -111,9 +108,7 @@ class RustMatrixAuthenticationService(
return passphrase
}
override fun getHomeserverDetails(): StateFlow<MatrixHomeServerDetails?> = currentHomeserver
override suspend fun setHomeserver(homeserver: String): Result<Unit> =
override suspend fun setHomeserver(homeserver: String): Result<MatrixHomeServerDetails> =
withContext(coroutineDispatchers.io) {
val emptySessionPath = rotateSessionPath()
runCatchingExceptions {
@ -122,8 +117,7 @@ class RustMatrixAuthenticationService(
}
currentClient = client
val homeServerDetails = client.homeserverLoginDetails().map()
currentHomeserver.value = homeServerDetails.copy(url = homeserver)
client.homeserverLoginDetails().map()
}.onFailure {
clear()
}.mapFailure { failure ->

View file

@ -16,10 +16,10 @@ import org.matrix.rustcomponents.sdk.OidcException
class AuthenticationExceptionMappingTest {
@Test
fun `mapping an exception with no message returns 'Unknown error' message`() {
fun `mapping an exception with no message returns null message`() {
val exception = Exception()
val mappedException = exception.mapAuthenticationException()
assertThat(mappedException.message).isEqualTo("Unknown error")
assertThat(mappedException.message).isNull()
}
@Test
@ -46,7 +46,7 @@ class AuthenticationExceptionMappingTest {
assertThat(ClientBuildException.Sdk("SDK issue").mapAuthenticationException())
.isException<AuthenticationException.Generic>("SDK issue")
assertThat(ClientBuildException.ServerUnreachable("Server unreachable").mapAuthenticationException())
.isException<AuthenticationException.Generic>("Server unreachable")
.isException<AuthenticationException.ServerUnreachable>("Server unreachable")
assertThat(ClientBuildException.SlidingSync("Sliding Sync").mapAuthenticationException())
.isException<AuthenticationException.Generic>("Sliding Sync")
assertThat(ClientBuildException.WellKnownDeserializationException("WellKnown Deserialization").mapAuthenticationException())