Merge pull request #3609 from element-hq/feature/bma/slidingSyncCheck

Remove supportSlidingSync boolean.
This commit is contained in:
Benoit Marty 2024-10-07 15:30:39 +02:00 committed by GitHub
commit de6b34dc7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 15 additions and 99 deletions

View file

@ -14,5 +14,4 @@ data class AccountProvider(
val isPublic: Boolean = false,
val isMatrixOrg: Boolean = false,
val isValid: Boolean = false,
val supportSlidingSync: Boolean = false,
)

View file

@ -15,8 +15,7 @@ open class AccountProviderProvider : PreviewParameterProvider<AccountProvider> {
get() = sequenceOf(
anAccountProvider(),
anAccountProvider().copy(subtitle = null),
anAccountProvider().copy(subtitle = null, title = "no.sliding.sync", supportSlidingSync = false),
anAccountProvider().copy(subtitle = null, title = "invalid", isValid = false, supportSlidingSync = false),
anAccountProvider().copy(subtitle = null, title = "invalid", isValid = false),
anAccountProvider().copy(subtitle = null, title = "Other", isPublic = false, isMatrixOrg = false),
// Add other state here
)
@ -28,5 +27,4 @@ fun anAccountProvider() = AccountProvider(
isPublic = true,
isMatrixOrg = true,
isValid = true,
supportSlidingSync = true,
)

View file

@ -12,6 +12,4 @@ data class HomeserverData(
val homeserverUrl: String,
// True if a wellknown file has been found and is valid. If false, it means that the [homeserverUrl] is valid
val isWellknownValid: Boolean,
// True if a wellknown file has been found and is valid and is claiming a sliding sync Url
val supportSlidingSync: Boolean,
)

View file

@ -29,7 +29,7 @@ class HomeserverResolver @Inject constructor(
private val dispatchers: CoroutineDispatchers,
private val wellknownRequest: WellknownRequest,
) {
suspend fun resolve(userInput: String): Flow<List<HomeserverData>> = flow {
fun resolve(userInput: String): Flow<List<HomeserverData>> = flow {
val flowContext = currentCoroutineContext()
val trimmedUserInput = userInput.trim()
if (trimmedUserInput.length < 4) return@flow
@ -46,13 +46,11 @@ class HomeserverResolver @Inject constructor(
}
val isValid = wellKnown?.isValid().orFalse()
if (isValid) {
val supportSlidingSync = wellKnown?.supportSlidingSync().orFalse()
// Emit the list as soon as possible
currentList.add(
HomeserverData(
homeserverUrl = url,
isWellknownValid = true,
supportSlidingSync = supportSlidingSync
)
)
withContext(flowContext) {
@ -68,7 +66,6 @@ class HomeserverResolver @Inject constructor(
HomeserverData(
homeserverUrl = trimmedUserInput,
isWellknownValid = false,
supportSlidingSync = false,
)
)
)

View file

@ -21,9 +21,6 @@ import kotlinx.serialization.Serializable
* "m.identity_server": {
* "base_url": "https://vector.im"
* },
* "org.matrix.msc3575.proxy": {
* "url": "https://slidingsync.lab.matrix.org"
* }
* }
* </pre>
* .
@ -34,14 +31,8 @@ data class WellKnown(
val homeServer: WellKnownBaseConfig? = null,
@SerialName("m.identity_server")
val identityServer: WellKnownBaseConfig? = null,
@SerialName("org.matrix.msc3575.proxy")
val slidingSyncProxy: WellKnownSlidingSyncConfig? = null,
) {
fun isValid(): Boolean {
return homeServer?.baseURL?.isNotBlank().orFalse()
}
fun supportSlidingSync(): Boolean {
return slidingSyncProxy?.url?.isNotBlank().orFalse()
}
}

View file

@ -1,17 +0,0 @@
/*
* Copyright 2023, 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only
* Please see LICENSE in the repository root for full details.
*/
package io.element.android.features.login.impl.resolver.network
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class WellKnownSlidingSyncConfig(
@SerialName("url")
val url: String? = null,
)

View file

@ -29,7 +29,6 @@ class ChangeAccountProviderPresenter @Inject constructor(
isPublic = true,
isMatrixOrg = true,
isValid = true,
supportSlidingSync = true,
)
),
changeServerState = changeServerState,

View file

@ -34,20 +34,18 @@ fun aSearchAccountProviderState(
fun aHomeserverDataList(): List<HomeserverData> {
return listOf(
aHomeserverData(isWellknownValid = true, supportSlidingSync = true),
aHomeserverData(homeserverUrl = "https://no.sliding.sync", isWellknownValid = true, supportSlidingSync = false),
aHomeserverData(homeserverUrl = "https://invalid", isWellknownValid = false, supportSlidingSync = false),
aHomeserverData(isWellknownValid = true),
aHomeserverData(homeserverUrl = "https://no.sliding.sync", isWellknownValid = true),
aHomeserverData(homeserverUrl = "https://invalid", isWellknownValid = false),
)
}
fun aHomeserverData(
homeserverUrl: String = AuthenticationConfig.MATRIX_ORG_URL,
isWellknownValid: Boolean = true,
supportSlidingSync: Boolean = true,
): HomeserverData {
return HomeserverData(
homeserverUrl = homeserverUrl,
isWellknownValid = isWellknownValid,
supportSlidingSync = supportSlidingSync,
)
}

View file

@ -196,7 +196,6 @@ private fun HomeserverData.toAccountProvider(): AccountProvider {
isPublic = isMatrixOrg,
isMatrixOrg = isMatrixOrg,
isValid = isWellknownValid,
supportSlidingSync = supportSlidingSync,
)
}

View file

@ -46,7 +46,6 @@ class ChangeAccountProviderPresenterTest {
isPublic = true,
isMatrixOrg = true,
isValid = true,
supportSlidingSync = true,
)
)
)

View file

@ -17,7 +17,6 @@ import io.element.android.features.login.impl.resolver.HomeserverResolver
import io.element.android.features.login.impl.resolver.network.FakeWellknownRequest
import io.element.android.features.login.impl.resolver.network.WellKnown
import io.element.android.features.login.impl.resolver.network.WellKnownBaseConfig
import io.element.android.features.login.impl.resolver.network.WellKnownSlidingSyncConfig
import io.element.android.libraries.architecture.AsyncData
import io.element.android.libraries.matrix.test.A_HOMESERVER_URL
import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationService
@ -98,7 +97,7 @@ class SearchAccountProviderPresenterTest {
assertThat(awaitItem().userInputResult).isEqualTo(
AsyncData.Success(
listOf(
aHomeserverData(homeserverUrl = "https://test.org", isWellknownValid = false, supportSlidingSync = false)
aHomeserverData(homeserverUrl = "https://test.org", isWellknownValid = false)
)
)
)
@ -106,42 +105,7 @@ class SearchAccountProviderPresenterTest {
}
@Test
fun `present - enter text one result no sliding sync`() = runTest {
val fakeWellknownRequest = FakeWellknownRequest()
fakeWellknownRequest.givenResultMap(
mapOf(
"https://test.org" to aWellKnown().copy(slidingSyncProxy = null),
)
)
val changeServerPresenter = ChangeServerPresenter(
FakeMatrixAuthenticationService(),
AccountProviderDataSource()
)
val presenter = SearchAccountProviderPresenter(
HomeserverResolver(testCoroutineDispatchers(), fakeWellknownRequest),
changeServerPresenter
)
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink.invoke(SearchAccountProviderEvents.UserInput("test"))
val withInputState = awaitItem()
assertThat(withInputState.userInput).isEqualTo("test")
assertThat(initialState.userInputResult).isEqualTo(AsyncData.Uninitialized)
assertThat(awaitItem().userInputResult).isInstanceOf(AsyncData.Loading::class.java)
assertThat(awaitItem().userInputResult).isEqualTo(
AsyncData.Success(
listOf(
aHomeserverData(homeserverUrl = "https://test.org", isWellknownValid = true, supportSlidingSync = false)
)
)
)
}
}
@Test
fun `present - enter text one result with sliding sync`() = runTest {
fun `present - enter text one result with wellknown`() = runTest {
val fakeWellknownRequest = FakeWellknownRequest()
fakeWellknownRequest.givenResultMap(
mapOf(
@ -183,9 +147,6 @@ class SearchAccountProviderPresenterTest {
identityServer = WellKnownBaseConfig(
baseURL = A_HOMESERVER_URL
),
slidingSyncProxy = WellKnownSlidingSyncConfig(
url = A_HOMESERVER_URL
)
)
}
}

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5395f34b153a3c453c95970f326e701e7e5619b53b9bf38dd6a9cff107e28407
size 8460
oid sha256:5fb195657c1ac0379839bba6acc0935f6b1b946714ba252d5797fd4bc0c514db
size 6753

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5fb195657c1ac0379839bba6acc0935f6b1b946714ba252d5797fd4bc0c514db
size 6753
oid sha256:6d742af6422e7f5ce0070831e921180006a5b48d52c042fdc52030435597f242
size 5835

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6d742af6422e7f5ce0070831e921180006a5b48d52c042fdc52030435597f242
size 5835

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:daed25bb59f0cca8d4bdb5139a177904a407b7d42f9e2d7053fd6f7362c141bf
size 8372
oid sha256:ec5654de38a98ee4b078aa3dfa093a686cb89a2f200eb69f59e78041eb8b2f60
size 6743

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ec5654de38a98ee4b078aa3dfa093a686cb89a2f200eb69f59e78041eb8b2f60
size 6743
oid sha256:b4731443df36855c8785072a8085fc9968ec231ff46ff24012b0ae72cd084e46
size 5867

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b4731443df36855c8785072a8085fc9968ec231ff46ff24012b0ae72cd084e46
size 5867