From 6d252c0b2044ef2c694e139cc71239f2f66ffc57 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 6 Nov 2025 12:22:48 +0100 Subject: [PATCH] MatrixAuthenticationService: remove `fun getHomeserverDetails(): StateFlow`. The MatrixHomeServerDetails are now return by `setHomeserver` --- .../login/impl/changeserver/ChangeServerPresenter.kt | 8 +++----- .../android/features/login/impl/login/LoginHelper.kt | 3 +-- .../matrix/api/auth/MatrixAuthenticationService.kt | 9 ++++++--- .../matrix/impl/auth/RustMatrixAuthenticationService.kt | 7 ++----- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt index 4df9eb12d5..d3db7496c5 100644 --- a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt +++ b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/changeserver/ChangeServerPresenter.kt @@ -60,11 +60,9 @@ class ChangeServerPresenter( title = data.title, accountProviderUrl = data.url, ) - authenticationService.setHomeserver(data.url).map { - authenticationService.getHomeserverDetails().value!! - // Valid, remember user choice - accountProviderDataSource.userSelection(data) - }.getOrThrow() + authenticationService.setHomeserver(data.url).getOrThrow() + // Homeserver is valid, remember user choice + accountProviderDataSource.userSelection(data) }.runCatchingUpdatingState(changeServerAction, errorTransform = ChangeServerError::from) } } diff --git a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/login/LoginHelper.kt b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/login/LoginHelper.kt index 82ee87c372..8dbd2a4df3 100644 --- a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/login/LoginHelper.kt +++ b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/login/LoginHelper.kt @@ -65,8 +65,7 @@ class LoginHelper( loginHint: String?, ) = coroutineScope.launch { suspend { - authenticationService.setHomeserver(homeserverUrl).map { - val matrixHomeServerDetails = authenticationService.getHomeserverDetails().value!! + authenticationService.setHomeserver(homeserverUrl).map { matrixHomeServerDetails -> if (matrixHomeServerDetails.supportsOidcLogin) { // Retrieve the details right now val oidcPrompt = if (isAccountCreation) OidcPrompt.Create else OidcPrompt.Login diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/auth/MatrixAuthenticationService.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/auth/MatrixAuthenticationService.kt index 38777944ee..1255e40a14 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/auth/MatrixAuthenticationService.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/auth/MatrixAuthenticationService.kt @@ -13,7 +13,6 @@ import io.element.android.libraries.matrix.api.auth.external.ExternalSession import io.element.android.libraries.matrix.api.auth.qrlogin.MatrixQrCodeLoginData import io.element.android.libraries.matrix.api.auth.qrlogin.QrCodeLoginStep import io.element.android.libraries.matrix.api.core.SessionId -import kotlinx.coroutines.flow.StateFlow interface MatrixAuthenticationService { /** @@ -22,8 +21,12 @@ interface MatrixAuthenticationService { * Generally this method should not be used directly, prefer using [MatrixClientProvider.getOrRestore] instead. */ suspend fun restoreSession(sessionId: SessionId): Result - fun getHomeserverDetails(): StateFlow - suspend fun setHomeserver(homeserver: String): Result + + /** + * Set the homeserver to use for authentication, and return its details. + */ + suspend fun setHomeserver(homeserver: String): Result + suspend fun login(username: String, password: String): Result /** diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt index 9859358ae6..7ed523812f 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt @@ -37,7 +37,6 @@ 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 @@ -111,9 +110,7 @@ class RustMatrixAuthenticationService( return passphrase } - override fun getHomeserverDetails(): StateFlow = currentHomeserver - - override suspend fun setHomeserver(homeserver: String): Result = + override suspend fun setHomeserver(homeserver: String): Result = withContext(coroutineDispatchers.io) { val emptySessionPath = rotateSessionPath() runCatchingExceptions { @@ -123,7 +120,7 @@ class RustMatrixAuthenticationService( currentClient = client val homeServerDetails = client.homeserverLoginDetails().map() - currentHomeserver.value = homeServerDetails.copy(url = homeserver) + homeServerDetails.copy(url = homeserver) }.onFailure { clear() }.mapFailure { failure ->