#1682: parse "default_server_config"
This commit is contained in:
parent
1b9b18851d
commit
c11c28b406
|
@ -176,10 +176,11 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { riotConfig ->
|
.map { riotConfig ->
|
||||||
if (riotConfig.defaultHomeServerUrl?.isNotBlank() == true) {
|
val defaultHomeServerUrl = riotConfig.getPreferredHomeServerUrl()
|
||||||
|
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(
|
||||||
homeServerUri = Uri.parse(riotConfig.defaultHomeServerUrl)
|
homeServerUri = Uri.parse(defaultHomeServerUrl)
|
||||||
)
|
)
|
||||||
|
|
||||||
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
|
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
|
||||||
|
@ -188,7 +189,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||||
apiCall = newAuthAPI.versions()
|
apiCall = newAuthAPI.versions()
|
||||||
}
|
}
|
||||||
|
|
||||||
getLoginFlowResult(newAuthAPI, versions, riotConfig.defaultHomeServerUrl)
|
getLoginFlowResult(newAuthAPI, versions, defaultHomeServerUrl)
|
||||||
} else {
|
} else {
|
||||||
// Config exists, but there is no default homeserver url (ex: https://riot.im/app)
|
// Config exists, but there is no default homeserver url (ex: https://riot.im/app)
|
||||||
throw Failure.OtherServerError("", HttpsURLConnection.HTTP_NOT_FOUND /* 404 */)
|
throw Failure.OtherServerError("", HttpsURLConnection.HTTP_NOT_FOUND /* 404 */)
|
||||||
|
|
|
@ -22,8 +22,30 @@ import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class RiotConfig(
|
data class RiotConfig(
|
||||||
// There are plenty of other elements in the file config.json of a RiotWeb client, but for the moment only one is interesting
|
/**
|
||||||
// Ex: "brand", "branding", etc.
|
* This is now deprecated, but still used first, rather than value from "default_server_config"
|
||||||
|
*/
|
||||||
@Json(name = "default_hs_url")
|
@Json(name = "default_hs_url")
|
||||||
val defaultHomeServerUrl: String?
|
val defaultHomeServerUrl: String?,
|
||||||
|
|
||||||
|
@Json(name = "default_server_config")
|
||||||
|
val defaultServerConfig: RiotConfigDefaultServerConfig?
|
||||||
|
) {
|
||||||
|
fun getPreferredHomeServerUrl(): String? {
|
||||||
|
return defaultHomeServerUrl
|
||||||
|
?.takeIf { it.isNotEmpty() }
|
||||||
|
?: defaultServerConfig?.homeServer?.baseURL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class RiotConfigDefaultServerConfig(
|
||||||
|
@Json(name = "m.homeserver")
|
||||||
|
val homeServer: RiotConfigBaseConfig? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class RiotConfigBaseConfig(
|
||||||
|
@Json(name = "base_url")
|
||||||
|
val baseURL: String? = null
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue