Remove Riot ref: Riot -> Web client

This commit is contained in:
Benoit Marty 2021-07-05 16:41:26 +02:00
parent 7292c4e13d
commit 67f41028ff
3 changed files with 28 additions and 28 deletions

View File

@ -21,8 +21,8 @@ import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.internal.auth.data.Availability import org.matrix.android.sdk.internal.auth.data.Availability
import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse
import org.matrix.android.sdk.internal.auth.data.PasswordLoginParams import org.matrix.android.sdk.internal.auth.data.PasswordLoginParams
import org.matrix.android.sdk.internal.auth.data.RiotConfig
import org.matrix.android.sdk.internal.auth.data.TokenLoginParams import org.matrix.android.sdk.internal.auth.data.TokenLoginParams
import org.matrix.android.sdk.internal.auth.data.WebClientConfig
import org.matrix.android.sdk.internal.auth.login.ResetPasswordMailConfirmed import org.matrix.android.sdk.internal.auth.login.ResetPasswordMailConfirmed
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationResponse import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationResponse
@ -44,16 +44,16 @@ import retrofit2.http.Url
*/ */
internal interface AuthAPI { internal interface AuthAPI {
/** /**
* Get a Riot config file, using the name including the domain * Get a Web client config file, using the name including the domain
*/ */
@GET("config.{domain}.json") @GET("config.{domain}.json")
suspend fun getRiotConfigDomain(@Path("domain") domain: String): RiotConfig suspend fun getWebClientConfigDomain(@Path("domain") domain: String): WebClientConfig
/** /**
* Get a Riot config file * Get a Web client default config file
*/ */
@GET("config.json") @GET("config.json")
suspend fun getRiotConfig(): RiotConfig suspend fun getWebClientConfig(): WebClientConfig
/** /**
* Get the version information of the homeserver * Get the version information of the homeserver

View File

@ -33,7 +33,7 @@ import org.matrix.android.sdk.api.failure.MatrixIdFailure
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.appendParamToUrl import org.matrix.android.sdk.api.util.appendParamToUrl
import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.SessionManager
import org.matrix.android.sdk.internal.auth.data.RiotConfig import org.matrix.android.sdk.internal.auth.data.WebClientConfig
import org.matrix.android.sdk.internal.auth.db.PendingSessionData import org.matrix.android.sdk.internal.auth.db.PendingSessionData
import org.matrix.android.sdk.internal.auth.login.DefaultLoginWizard import org.matrix.android.sdk.internal.auth.login.DefaultLoginWizard
import org.matrix.android.sdk.internal.auth.login.DirectLoginTask import org.matrix.android.sdk.internal.auth.login.DirectLoginTask
@ -145,7 +145,7 @@ internal class DefaultAuthenticationService @Inject constructor(
return result.fold( return result.fold(
{ {
// The homeserver exists and up to date, keep the config // The homeserver exists and up to date, keep the config
// Homeserver url may have been changed, if it was a Riot url // Homeserver url may have been changed, if it was a Web client url
val alteredHomeServerConnectionConfig = homeServerConnectionConfig.copy( val alteredHomeServerConnectionConfig = homeServerConnectionConfig.copy(
homeServerUriBase = Uri.parse(it.homeServerUrl) homeServerUriBase = Uri.parse(it.homeServerUrl)
) )
@ -191,8 +191,8 @@ internal class DefaultAuthenticationService @Inject constructor(
{ {
if (it is Failure.OtherServerError if (it is Failure.OtherServerError
&& it.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) { && it.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) {
// It's maybe a Riot url? // It's maybe a Web client url?
getRiotDomainLoginFlowInternal(homeServerConnectionConfig) getWebClientDomainLoginFlowInternal(homeServerConnectionConfig)
} else { } else {
throw it throw it
} }
@ -204,20 +204,20 @@ internal class DefaultAuthenticationService @Inject constructor(
} }
} }
private suspend fun getRiotDomainLoginFlowInternal(homeServerConnectionConfig: HomeServerConnectionConfig): LoginFlowResult { private suspend fun getWebClientDomainLoginFlowInternal(homeServerConnectionConfig: HomeServerConnectionConfig): LoginFlowResult {
val authAPI = buildAuthAPI(homeServerConnectionConfig) val authAPI = buildAuthAPI(homeServerConnectionConfig)
val domain = homeServerConnectionConfig.homeServerUri.host val domain = homeServerConnectionConfig.homeServerUri.host
?: return getRiotLoginFlowInternal(homeServerConnectionConfig) ?: return getWebClientLoginFlowInternal(homeServerConnectionConfig)
// Ok, try to get the config.domain.json file of a RiotWeb client // Ok, try to get the config.domain.json file of a Web client
return runCatching { return runCatching {
executeRequest(null) { executeRequest(null) {
authAPI.getRiotConfigDomain(domain) authAPI.getWebClientConfigDomain(domain)
} }
} }
.map { riotConfig -> .map { webClientConfig ->
onRiotConfigRetrieved(homeServerConnectionConfig, riotConfig) onWebClientConfigRetrieved(homeServerConnectionConfig, webClientConfig)
} }
.fold( .fold(
{ {
@ -227,7 +227,7 @@ internal class DefaultAuthenticationService @Inject constructor(
if (it is Failure.OtherServerError if (it is Failure.OtherServerError
&& it.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) { && it.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) {
// Try with config.json // Try with config.json
getRiotLoginFlowInternal(homeServerConnectionConfig) getWebClientLoginFlowInternal(homeServerConnectionConfig)
} else { } else {
throw it throw it
} }
@ -235,20 +235,20 @@ internal class DefaultAuthenticationService @Inject constructor(
) )
} }
private suspend fun getRiotLoginFlowInternal(homeServerConnectionConfig: HomeServerConnectionConfig): LoginFlowResult { private suspend fun getWebClientLoginFlowInternal(homeServerConnectionConfig: HomeServerConnectionConfig): LoginFlowResult {
val authAPI = buildAuthAPI(homeServerConnectionConfig) val authAPI = buildAuthAPI(homeServerConnectionConfig)
// Ok, try to get the config.json file of a RiotWeb client // Ok, try to get the config.json file of a Web client
return executeRequest(null) { return executeRequest(null) {
authAPI.getRiotConfig() authAPI.getWebClientConfig()
} }
.let { riotConfig -> .let { webClientConfig ->
onRiotConfigRetrieved(homeServerConnectionConfig, riotConfig) onWebClientConfigRetrieved(homeServerConnectionConfig, webClientConfig)
} }
} }
private suspend fun onRiotConfigRetrieved(homeServerConnectionConfig: HomeServerConnectionConfig, riotConfig: RiotConfig): LoginFlowResult { private suspend fun onWebClientConfigRetrieved(homeServerConnectionConfig: HomeServerConnectionConfig, webClientConfig: WebClientConfig): LoginFlowResult {
val defaultHomeServerUrl = riotConfig.getPreferredHomeServerUrl() val defaultHomeServerUrl = webClientConfig.getPreferredHomeServerUrl()
if (defaultHomeServerUrl?.isNotEmpty() == true) { if (defaultHomeServerUrl?.isNotEmpty() == true) {
// Ok, good sign, we got a default hs url // Ok, good sign, we got a default hs url
val newHomeServerConnectionConfig = homeServerConnectionConfig.copy( val newHomeServerConnectionConfig = homeServerConnectionConfig.copy(

View File

@ -20,7 +20,7 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
internal data class RiotConfig( internal data class WebClientConfig(
/** /**
* This is now deprecated, but still used first, rather than value from "default_server_config" * This is now deprecated, but still used first, rather than value from "default_server_config"
*/ */
@ -28,7 +28,7 @@ internal data class RiotConfig(
val defaultHomeServerUrl: String?, val defaultHomeServerUrl: String?,
@Json(name = "default_server_config") @Json(name = "default_server_config")
val defaultServerConfig: RiotConfigDefaultServerConfig? val defaultServerConfig: WebClientConfigDefaultServerConfig?
) { ) {
fun getPreferredHomeServerUrl(): String? { fun getPreferredHomeServerUrl(): String? {
return defaultHomeServerUrl return defaultHomeServerUrl
@ -38,13 +38,13 @@ internal data class RiotConfig(
} }
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
internal data class RiotConfigDefaultServerConfig( internal data class WebClientConfigDefaultServerConfig(
@Json(name = "m.homeserver") @Json(name = "m.homeserver")
val homeServer: RiotConfigBaseConfig? = null val homeServer: WebClientConfigBaseConfig? = null
) )
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
internal data class RiotConfigBaseConfig( internal data class WebClientConfigBaseConfig(
@Json(name = "base_url") @Json(name = "base_url")
val baseURL: String? = null val baseURL: String? = null
) )