MatrixAuthenticationService: remove fun getHomeserverDetails(): StateFlow<MatrixHomeServerDetails?>. The MatrixHomeServerDetails are now return by setHomeserver
This commit is contained in:
parent
c0800e102a
commit
6d252c0b20
4 changed files with 12 additions and 15 deletions
|
|
@ -60,11 +60,9 @@ class ChangeServerPresenter(
|
||||||
title = data.title,
|
title = data.title,
|
||||||
accountProviderUrl = data.url,
|
accountProviderUrl = data.url,
|
||||||
)
|
)
|
||||||
authenticationService.setHomeserver(data.url).map {
|
authenticationService.setHomeserver(data.url).getOrThrow()
|
||||||
authenticationService.getHomeserverDetails().value!!
|
// Homeserver is valid, remember user choice
|
||||||
// Valid, remember user choice
|
accountProviderDataSource.userSelection(data)
|
||||||
accountProviderDataSource.userSelection(data)
|
|
||||||
}.getOrThrow()
|
|
||||||
}.runCatchingUpdatingState(changeServerAction, errorTransform = ChangeServerError::from)
|
}.runCatchingUpdatingState(changeServerAction, errorTransform = ChangeServerError::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,7 @@ class LoginHelper(
|
||||||
loginHint: String?,
|
loginHint: String?,
|
||||||
) = coroutineScope.launch {
|
) = coroutineScope.launch {
|
||||||
suspend {
|
suspend {
|
||||||
authenticationService.setHomeserver(homeserverUrl).map {
|
authenticationService.setHomeserver(homeserverUrl).map { matrixHomeServerDetails ->
|
||||||
val matrixHomeServerDetails = authenticationService.getHomeserverDetails().value!!
|
|
||||||
if (matrixHomeServerDetails.supportsOidcLogin) {
|
if (matrixHomeServerDetails.supportsOidcLogin) {
|
||||||
// Retrieve the details right now
|
// Retrieve the details right now
|
||||||
val oidcPrompt = if (isAccountCreation) OidcPrompt.Create else OidcPrompt.Login
|
val oidcPrompt = if (isAccountCreation) OidcPrompt.Create else OidcPrompt.Login
|
||||||
|
|
|
||||||
|
|
@ -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.MatrixQrCodeLoginData
|
||||||
import io.element.android.libraries.matrix.api.auth.qrlogin.QrCodeLoginStep
|
import io.element.android.libraries.matrix.api.auth.qrlogin.QrCodeLoginStep
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
|
|
||||||
interface MatrixAuthenticationService {
|
interface MatrixAuthenticationService {
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,8 +21,12 @@ interface MatrixAuthenticationService {
|
||||||
* Generally this method should not be used directly, prefer using [MatrixClientProvider.getOrRestore] instead.
|
* Generally this method should not be used directly, prefer using [MatrixClientProvider.getOrRestore] instead.
|
||||||
*/
|
*/
|
||||||
suspend fun restoreSession(sessionId: SessionId): Result<MatrixClient>
|
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>
|
suspend fun login(username: String, password: String): Result<SessionId>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ import io.element.android.libraries.sessionstorage.api.LoginType
|
||||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.matrix.rustcomponents.sdk.Client
|
import org.matrix.rustcomponents.sdk.Client
|
||||||
import org.matrix.rustcomponents.sdk.ClientBuilder
|
import org.matrix.rustcomponents.sdk.ClientBuilder
|
||||||
|
|
@ -111,9 +110,7 @@ class RustMatrixAuthenticationService(
|
||||||
return passphrase
|
return passphrase
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getHomeserverDetails(): StateFlow<MatrixHomeServerDetails?> = currentHomeserver
|
override suspend fun setHomeserver(homeserver: String): Result<MatrixHomeServerDetails> =
|
||||||
|
|
||||||
override suspend fun setHomeserver(homeserver: String): Result<Unit> =
|
|
||||||
withContext(coroutineDispatchers.io) {
|
withContext(coroutineDispatchers.io) {
|
||||||
val emptySessionPath = rotateSessionPath()
|
val emptySessionPath = rotateSessionPath()
|
||||||
runCatchingExceptions {
|
runCatchingExceptions {
|
||||||
|
|
@ -123,7 +120,7 @@ class RustMatrixAuthenticationService(
|
||||||
|
|
||||||
currentClient = client
|
currentClient = client
|
||||||
val homeServerDetails = client.homeserverLoginDetails().map()
|
val homeServerDetails = client.homeserverLoginDetails().map()
|
||||||
currentHomeserver.value = homeServerDetails.copy(url = homeserver)
|
homeServerDetails.copy(url = homeserver)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
clear()
|
clear()
|
||||||
}.mapFailure { failure ->
|
}.mapFailure { failure ->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue