mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Move class Versions to internal package
This commit is contained in:
parent
57a5714fb5
commit
532f5e58ea
7 changed files with 27 additions and 27 deletions
|
@ -17,7 +17,6 @@
|
|||
package im.vector.matrix.android.internal.auth
|
||||
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.auth.data.Versions
|
||||
import im.vector.matrix.android.internal.auth.data.LoginFlowResponse
|
||||
import im.vector.matrix.android.internal.auth.data.PasswordLoginParams
|
||||
import im.vector.matrix.android.internal.auth.data.RiotConfig
|
||||
|
@ -27,6 +26,7 @@ import im.vector.matrix.android.internal.auth.registration.AddThreePidRegistrati
|
|||
import im.vector.matrix.android.internal.auth.registration.RegistrationParams
|
||||
import im.vector.matrix.android.internal.auth.registration.SuccessResult
|
||||
import im.vector.matrix.android.internal.auth.registration.ValidationCodeBody
|
||||
import im.vector.matrix.android.internal.auth.version.Versions
|
||||
import im.vector.matrix.android.internal.network.NetworkConstants
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.Body
|
||||
|
|
|
@ -23,9 +23,6 @@ import im.vector.matrix.android.api.auth.AuthenticationService
|
|||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.api.auth.data.LoginFlowResult
|
||||
import im.vector.matrix.android.api.auth.data.Versions
|
||||
import im.vector.matrix.android.api.auth.data.isLoginAndRegistrationSupportedBySdk
|
||||
import im.vector.matrix.android.api.auth.data.isSupportedBySdk
|
||||
import im.vector.matrix.android.api.auth.login.LoginWizard
|
||||
import im.vector.matrix.android.api.auth.registration.RegistrationWizard
|
||||
import im.vector.matrix.android.api.auth.wellknown.WellknownResult
|
||||
|
@ -40,6 +37,9 @@ import im.vector.matrix.android.internal.auth.db.PendingSessionData
|
|||
import im.vector.matrix.android.internal.auth.login.DefaultLoginWizard
|
||||
import im.vector.matrix.android.internal.auth.login.DirectLoginTask
|
||||
import im.vector.matrix.android.internal.auth.registration.DefaultRegistrationWizard
|
||||
import im.vector.matrix.android.internal.auth.version.Versions
|
||||
import im.vector.matrix.android.internal.auth.version.isLoginAndRegistrationSupportedBySdk
|
||||
import im.vector.matrix.android.internal.auth.version.isSupportedBySdk
|
||||
import im.vector.matrix.android.internal.di.Unauthenticated
|
||||
import im.vector.matrix.android.internal.network.RetrofitFactory
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
|
|
|
@ -48,5 +48,13 @@ internal data class HomeServerVersion(
|
|||
patch = result.groupValues[3].toInt()
|
||||
)
|
||||
}
|
||||
|
||||
val r0_0_1 = parse("r0.0.1")!!
|
||||
val r0_1_0 = parse("r0.1.0")!!
|
||||
val r0_2_0 = parse("r0.2.0")!!
|
||||
val r0_3_0 = parse("r0.3.0")!!
|
||||
val r0_4_0 = parse("r0.4.0")!!
|
||||
val r0_5_0 = parse("r0.5.0")!!
|
||||
val r0_6_0 = parse("r0.6.0")!!
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2018 New Vector Ltd
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,11 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.matrix.android.api.auth.data
|
||||
package im.vector.matrix.android.internal.auth.version
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.internal.auth.version.HomeServerVersion
|
||||
|
||||
/**
|
||||
* Model for https://matrix.org/docs/spec/client_server/latest#get-matrix-client-versions
|
||||
|
@ -39,7 +38,7 @@ import im.vector.matrix.android.internal.auth.version.HomeServerVersion
|
|||
* </pre>
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Versions(
|
||||
internal data class Versions(
|
||||
@Json(name = "versions")
|
||||
val supportedVersions: List<String>? = null,
|
||||
|
||||
|
@ -47,15 +46,6 @@ data class Versions(
|
|||
val unstableFeatures: Map<String, Boolean>? = null
|
||||
)
|
||||
|
||||
// MatrixClientServerAPIVersion
|
||||
private val r0_0_1 = HomeServerVersion.parse("r0.0.1")!!
|
||||
private val r0_1_0 = HomeServerVersion.parse("r0.1.0")!!
|
||||
private val r0_2_0 = HomeServerVersion.parse("r0.2.0")!!
|
||||
private val r0_3_0 = HomeServerVersion.parse("r0.3.0")!!
|
||||
private val r0_4_0 = HomeServerVersion.parse("r0.4.0")!!
|
||||
private val r0_5_0 = HomeServerVersion.parse("r0.5.0")!!
|
||||
private val r0_6_0 = HomeServerVersion.parse("r0.6.0")!!
|
||||
|
||||
// MatrixVersionsFeature
|
||||
private const val FEATURE_LAZY_LOAD_MEMBERS = "m.lazy_load_members"
|
||||
private const val FEATURE_REQUIRE_IDENTITY_SERVER = "m.require_identity_server"
|
||||
|
@ -65,14 +55,14 @@ private const val FEATURE_SEPARATE_ADD_AND_BIND = "m.separate_add_and_bind"
|
|||
/**
|
||||
* Return true if the SDK supports this homeserver version
|
||||
*/
|
||||
fun Versions.isSupportedBySdk(): Boolean {
|
||||
internal fun Versions.isSupportedBySdk(): Boolean {
|
||||
return supportLazyLoadMembers()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the SDK supports this homeserver version for login and registration
|
||||
*/
|
||||
fun Versions.isLoginAndRegistrationSupportedBySdk(): Boolean {
|
||||
internal fun Versions.isLoginAndRegistrationSupportedBySdk(): Boolean {
|
||||
return !doesServerRequireIdentityServerParam()
|
||||
&& doesServerAcceptIdentityAccessToken()
|
||||
&& doesServerSeparatesAddAndBind()
|
||||
|
@ -84,7 +74,7 @@ fun Versions.isLoginAndRegistrationSupportedBySdk(): Boolean {
|
|||
* @return true if the server support the lazy loading of room members
|
||||
*/
|
||||
private fun Versions.supportLazyLoadMembers(): Boolean {
|
||||
return getMaxVersion() >= r0_5_0
|
||||
return getMaxVersion() >= HomeServerVersion.r0_5_0
|
||||
|| unstableFeatures?.get(FEATURE_LAZY_LOAD_MEMBERS) == true
|
||||
}
|
||||
|
||||
|
@ -93,7 +83,7 @@ private fun Versions.supportLazyLoadMembers(): Boolean {
|
|||
* adding a 3pid or resetting password.
|
||||
*/
|
||||
private fun Versions.doesServerRequireIdentityServerParam(): Boolean {
|
||||
if (getMaxVersion() >= r0_6_0) return false
|
||||
if (getMaxVersion() >= HomeServerVersion.r0_6_0) return false
|
||||
return unstableFeatures?.get(FEATURE_REQUIRE_IDENTITY_SERVER) ?: true
|
||||
}
|
||||
|
||||
|
@ -102,12 +92,12 @@ private fun Versions.doesServerRequireIdentityServerParam(): Boolean {
|
|||
* Some homeservers may trigger errors if they are not prepared for the new parameter.
|
||||
*/
|
||||
private fun Versions.doesServerAcceptIdentityAccessToken(): Boolean {
|
||||
return getMaxVersion() >= r0_6_0
|
||||
return getMaxVersion() >= HomeServerVersion.r0_6_0
|
||||
|| unstableFeatures?.get(FEATURE_ID_ACCESS_TOKEN) ?: false
|
||||
}
|
||||
|
||||
private fun Versions.doesServerSeparatesAddAndBind(): Boolean {
|
||||
return getMaxVersion() >= r0_6_0
|
||||
return getMaxVersion() >= HomeServerVersion.r0_6_0
|
||||
|| unstableFeatures?.get(FEATURE_SEPARATE_ADD_AND_BIND) ?: false
|
||||
}
|
||||
|
||||
|
@ -115,5 +105,5 @@ private fun Versions.getMaxVersion(): HomeServerVersion {
|
|||
return supportedVersions
|
||||
?.mapNotNull { HomeServerVersion.parse(it) }
|
||||
?.max()
|
||||
?: r0_0_1
|
||||
?: HomeServerVersion.r0_0_1
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.internal.session.homeserver
|
||||
|
||||
import im.vector.matrix.android.api.auth.data.Versions
|
||||
import im.vector.matrix.android.internal.auth.version.Versions
|
||||
import im.vector.matrix.android.internal.network.NetworkConstants
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.GET
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
package im.vector.matrix.android.internal.session.homeserver
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.api.auth.data.Versions
|
||||
import im.vector.matrix.android.api.auth.data.isLoginAndRegistrationSupportedBySdk
|
||||
import im.vector.matrix.android.api.auth.wellknown.WellknownResult
|
||||
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities
|
||||
import im.vector.matrix.android.internal.auth.version.Versions
|
||||
import im.vector.matrix.android.internal.auth.version.isLoginAndRegistrationSupportedBySdk
|
||||
import im.vector.matrix.android.internal.database.model.HomeServerCapabilitiesEntity
|
||||
import im.vector.matrix.android.internal.database.query.getOrCreate
|
||||
import im.vector.matrix.android.internal.di.UserId
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package im.vector.matrix.android.api.auth.data
|
||||
|
||||
import im.vector.matrix.android.internal.auth.version.Versions
|
||||
import im.vector.matrix.android.internal.auth.version.isSupportedBySdk
|
||||
import org.amshove.kluent.shouldBe
|
||||
import org.junit.Test
|
||||
|
||||
|
|
Loading…
Reference in a new issue