Fix wrong versioning regex pattern

Add MSC3440 support using /version/ and /capabilities
This commit is contained in:
ariskotsomitopoulos 2022-03-05 17:13:02 +02:00
parent daafddbe71
commit bce5bc8389
7 changed files with 32 additions and 5 deletions

View File

@ -42,7 +42,7 @@ interface ThreadsService {
* message edition for that thread
* @return the enhanced [List] with edited updates
*/
fun enhanceWithEditions(threads: List<ThreadSummary>): List<ThreadSummary>
fun enhanceThreadWithEditions(threads: List<ThreadSummary>): List<ThreadSummary>
/**
* Fetch all thread replies for the specified thread using the /relations api

View File

@ -38,7 +38,7 @@ internal data class HomeServerVersion(
}
companion object {
internal val pattern = Regex("""r(\d+)\.(\d+)\.(\d+)""")
internal val pattern = Regex("""[r|v](\d+)\.(\d+)\.(\d+)""")
internal fun parse(value: String): HomeServerVersion? {
val result = pattern.matchEntire(value) ?: return null
@ -56,5 +56,6 @@ internal data class HomeServerVersion(
val r0_4_0 = HomeServerVersion(major = 0, minor = 4, patch = 0)
val r0_5_0 = HomeServerVersion(major = 0, minor = 5, patch = 0)
val r0_6_0 = HomeServerVersion(major = 0, minor = 6, patch = 0)
val v1_3_0 = HomeServerVersion(major = 1, minor = 3, patch = 0)
}
}

View File

@ -51,6 +51,7 @@ private const val FEATURE_LAZY_LOAD_MEMBERS = "m.lazy_load_members"
private const val FEATURE_REQUIRE_IDENTITY_SERVER = "m.require_identity_server"
private const val FEATURE_ID_ACCESS_TOKEN = "m.id_access_token"
private const val FEATURE_SEPARATE_ADD_AND_BIND = "m.separate_add_and_bind"
private const val FEATURE_THREADS_MSC3440 = "org.matrix.msc3440"
/**
* Return true if the SDK supports this homeserver version
@ -68,6 +69,14 @@ internal fun Versions.isLoginAndRegistrationSupportedBySdk(): Boolean {
doesServerSeparatesAddAndBind()
}
/**
* Indicate if the homeserver support MSC3440 for threads
*/
internal fun Versions.doesServerSupportThreads(): Boolean {
return getMaxVersion() >= HomeServerVersion.v1_3_0 ||
unstableFeatures?.get(FEATURE_THREADS_MSC3440) ?: false
}
/**
* Return true if the server support the lazy loading of room members
*

View File

@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.extensions.orTrue
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
import org.matrix.android.sdk.internal.auth.version.Versions
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreads
import org.matrix.android.sdk.internal.auth.version.isLoginAndRegistrationSupportedBySdk
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity
import org.matrix.android.sdk.internal.database.query.getOrCreate
@ -122,7 +123,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
homeServerCapabilitiesEntity.roomVersionsJson = capabilities?.roomVersions?.let {
MoshiProvider.providesMoshi().adapter(RoomVersions::class.java).toJson(it)
}
homeServerCapabilitiesEntity.canUseThreading = capabilities?.threads?.enabled.orFalse()
homeServerCapabilitiesEntity.canUseThreading = capabilities?.threads?.enabled.orFalse() || getVersionResult?.doesServerSupportThreads().orFalse()
}
if (getMediaConfigResult != null) {

View File

@ -65,7 +65,7 @@ internal class DefaultThreadsService @AssistedInject constructor(
)
}
override fun enhanceWithEditions(threads: List<ThreadSummary>): List<ThreadSummary> {
override fun enhanceThreadWithEditions(threads: List<ThreadSummary>): List<ThreadSummary> {
return Realm.getInstance(monarchy.realmConfiguration).use {
threads.enhanceWithEditions(it, roomId)
}

View File

@ -19,6 +19,7 @@ package org.matrix.android.sdk.api.auth.data
import org.amshove.kluent.shouldBe
import org.junit.Test
import org.matrix.android.sdk.internal.auth.version.Versions
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreads
import org.matrix.android.sdk.internal.auth.version.isSupportedBySdk
class VersionsKtTest {
@ -53,5 +54,20 @@ class VersionsKtTest {
Versions(supportedVersions = listOf("r0.5.0", "r0.6.0")).isSupportedBySdk() shouldBe true
Versions(supportedVersions = listOf("r0.5.0", "r0.6.1")).isSupportedBySdk() shouldBe true
Versions(supportedVersions = listOf("r0.6.0")).isSupportedBySdk() shouldBe true
Versions(supportedVersions = listOf("v1.6.0")).isSupportedBySdk() shouldBe true
}
@Test
fun doesServerSupportThreads() {
Versions(supportedVersions = listOf("r0.6.0")).doesServerSupportThreads() shouldBe false
Versions(supportedVersions = listOf("r0.9.1")).doesServerSupportThreads() shouldBe false
Versions(supportedVersions = listOf("v1.2.0")).doesServerSupportThreads() shouldBe false
Versions(supportedVersions = listOf("v1.3.0")).doesServerSupportThreads() shouldBe true
Versions(supportedVersions = listOf("v1.3.1")).doesServerSupportThreads() shouldBe true
Versions(supportedVersions = listOf("v1.5.1")).doesServerSupportThreads() shouldBe true
Versions(supportedVersions = listOf("r0.6.0"), unstableFeatures = mapOf("org.matrix.msc3440" to true)).doesServerSupportThreads() shouldBe true
Versions(supportedVersions = listOf("v1.2.1"), unstableFeatures = mapOf("org.matrix.msc3440" to true)).doesServerSupportThreads() shouldBe true
Versions(supportedVersions = listOf("r0.6.0"), unstableFeatures = mapOf("org.matrix.msc3440" to false)).doesServerSupportThreads() shouldBe false
Versions(supportedVersions = listOf("v1.4.0"), unstableFeatures = mapOf("org.matrix.msc3440" to false)).doesServerSupportThreads() shouldBe true
}
}

View File

@ -80,7 +80,7 @@ class ThreadListViewModel @AssistedInject constructor(@Assisted val initialState
private fun observeThreadSummaries() {
room?.flow()
?.liveThreadSummaries()
?.map { room.enhanceWithEditions(it) }
?.map { room.enhanceThreadWithEditions(it) }
?.flowOn(room.coroutineDispatchers.io)
?.execute { asyncThreads ->
copy(threadSummaryList = asyncThreads)