From 532f5e58eaaeb2ef78f777573922873a40a015ce Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 4 Jun 2020 11:30:24 +0200 Subject: [PATCH] Move class Versions to internal package --- .../matrix/android/internal/auth/AuthAPI.kt | 2 +- .../auth/DefaultAuthenticationService.kt | 6 ++-- .../auth/version/HomeServerVersion.kt | 8 +++++ .../auth/version}/Versions.kt | 30 +++++++------------ .../session/homeserver/CapabilitiesAPI.kt | 2 +- .../DefaultGetHomeServerCapabilitiesTask.kt | 4 +-- .../android/api/auth/data/VersionsKtTest.kt | 2 ++ 7 files changed, 27 insertions(+), 27 deletions(-) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/{api/auth/data => internal/auth/version}/Versions.kt (77%) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthAPI.kt index 2f03c99421..7eaadd8ee2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthAPI.kt @@ -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 diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt index b543fa7507..5e80acf0f6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticationService.kt @@ -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 diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/version/HomeServerVersion.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/version/HomeServerVersion.kt index 0ea230774e..514f29a550 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/version/HomeServerVersion.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/version/HomeServerVersion.kt @@ -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")!! } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/Versions.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/version/Versions.kt similarity index 77% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/Versions.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/version/Versions.kt index e17209b316..a65be58e54 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/Versions.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/version/Versions.kt @@ -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 * */ @JsonClass(generateAdapter = true) -data class Versions( +internal data class Versions( @Json(name = "versions") val supportedVersions: List? = null, @@ -47,15 +46,6 @@ data class Versions( val unstableFeatures: Map? = 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 } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/CapabilitiesAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/CapabilitiesAPI.kt index 880a8fbc31..f96863bea6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/CapabilitiesAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/CapabilitiesAPI.kt @@ -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 diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt index 56b9dfc294..f1ee8b4583 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt @@ -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 diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/auth/data/VersionsKtTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/auth/data/VersionsKtTest.kt index b129c019b5..fa6e47f96d 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/auth/data/VersionsKtTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/auth/data/VersionsKtTest.kt @@ -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