mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +03:00
#1682: parse "default_server_config"
This commit is contained in:
parent
1b9b18851d
commit
c11c28b406
2 changed files with 29 additions and 6 deletions
|
@ -176,10 +176,11 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||
}
|
||||
}
|
||||
.map { riotConfig ->
|
||||
if (riotConfig.defaultHomeServerUrl?.isNotBlank() == true) {
|
||||
val defaultHomeServerUrl = riotConfig.getPreferredHomeServerUrl()
|
||||
if (defaultHomeServerUrl?.isNotEmpty() == true) {
|
||||
// Ok, good sign, we got a default hs url
|
||||
val newHomeServerConnectionConfig = homeServerConnectionConfig.copy(
|
||||
homeServerUri = Uri.parse(riotConfig.defaultHomeServerUrl)
|
||||
homeServerUri = Uri.parse(defaultHomeServerUrl)
|
||||
)
|
||||
|
||||
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
|
||||
|
@ -188,7 +189,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||
apiCall = newAuthAPI.versions()
|
||||
}
|
||||
|
||||
getLoginFlowResult(newAuthAPI, versions, riotConfig.defaultHomeServerUrl)
|
||||
getLoginFlowResult(newAuthAPI, versions, defaultHomeServerUrl)
|
||||
} else {
|
||||
// Config exists, but there is no default homeserver url (ex: https://riot.im/app)
|
||||
throw Failure.OtherServerError("", HttpsURLConnection.HTTP_NOT_FOUND /* 404 */)
|
||||
|
|
|
@ -22,8 +22,30 @@ import com.squareup.moshi.JsonClass
|
|||
|
||||
@JsonClass(generateAdapter = true)
|
||||
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")
|
||||
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 a new issue