MatrixAuthenticationService: remove fun getHomeserverDetails(): StateFlow<MatrixHomeServerDetails?>. The MatrixHomeServerDetails are now return by setHomeserver

This commit is contained in:
Benoit Marty
2025-11-06 12:22:48 +01:00
parent c0800e102a
commit 6d252c0b20
4 changed files with 12 additions and 15 deletions

View File

@@ -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)
}
}

View File

@@ -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

View File

@@ -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<MatrixClient>
fun getHomeserverDetails(): StateFlow<MatrixHomeServerDetails?>
suspend fun setHomeserver(homeserver: String): Result<Unit>
/**
* Set the homeserver to use for authentication, and return its details.
*/
suspend fun setHomeserver(homeserver: String): Result<MatrixHomeServerDetails>
suspend fun login(username: String, password: String): Result<SessionId>
/**

View File

@@ -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<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 {
@@ -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 ->