Skip to content

Commit 6bc579a

Browse files
committed
Adapt to SDK changes:
- Remove logic related to sliding sync proxy, leaving just the minimum needed to detect its usage on the current session data. - Remove code associated with the opt-in migration to native sliding sync, since it's now mandatory. - Remove toggle between proxy/native sliding sync. - Some fixes to session verification API breaks.
1 parent 8d5e45f commit 6bc579a

File tree

30 files changed

+28
-351
lines changed

30 files changed

+28
-351
lines changed

appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt

-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ import io.element.android.libraries.matrix.api.core.toRoomIdOrAlias
7575
import io.element.android.libraries.matrix.api.permalink.PermalinkData
7676
import io.element.android.libraries.matrix.api.verification.SessionVerificationRequestDetails
7777
import io.element.android.libraries.matrix.api.verification.SessionVerificationServiceListener
78-
import io.element.android.libraries.preferences.api.store.EnableNativeSlidingSyncUseCase
7978
import io.element.android.services.appnavstate.api.AppNavigationStateService
8079
import kotlinx.coroutines.CoroutineScope
8180
import kotlinx.coroutines.flow.launchIn
@@ -105,7 +104,6 @@ class LoggedInFlowNode @AssistedInject constructor(
105104
private val sendingQueue: SendQueues,
106105
private val logoutEntryPoint: LogoutEntryPoint,
107106
private val incomingVerificationEntryPoint: IncomingVerificationEntryPoint,
108-
private val enableNativeSlidingSyncUseCase: EnableNativeSlidingSyncUseCase,
109107
snackbarDispatcher: SnackbarDispatcher,
110108
) : BaseFlowNode<LoggedInFlowNode.NavTarget>(
111109
backstack = BackStack(
@@ -420,9 +418,6 @@ class LoggedInFlowNode @AssistedInject constructor(
420418
}
421419

422420
logoutEntryPoint.nodeBuilder(this, buildContext)
423-
.onSuccessfulLogoutPendingAction {
424-
enableNativeSlidingSyncUseCase()
425-
}
426421
.callback(callback)
427422
.build()
428423
}

appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInPresenter.kt

+5-15
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import io.element.android.libraries.matrix.api.sync.SyncService
3131
import io.element.android.libraries.matrix.api.sync.isOnline
3232
import io.element.android.libraries.matrix.api.verification.SessionVerificationService
3333
import io.element.android.libraries.matrix.api.verification.SessionVerifiedStatus
34-
import io.element.android.libraries.preferences.api.store.EnableNativeSlidingSyncUseCase
3534
import io.element.android.libraries.push.api.PushService
3635
import io.element.android.libraries.pushproviders.api.RegistrationFailure
3736
import io.element.android.services.analytics.api.AnalyticsService
@@ -51,7 +50,6 @@ class LoggedInPresenter @Inject constructor(
5150
private val sessionVerificationService: SessionVerificationService,
5251
private val analyticsService: AnalyticsService,
5352
private val encryptionService: EncryptionService,
54-
private val enableNativeSlidingSyncUseCase: EnableNativeSlidingSyncUseCase,
5553
) : Presenter<LoggedInState> {
5654
@Composable
5755
override fun present(): LoggedInState {
@@ -103,12 +101,10 @@ class LoggedInPresenter @Inject constructor(
103101
}
104102
}
105103
LoggedInEvents.CheckSlidingSyncProxyAvailability -> coroutineScope.launch {
106-
forceNativeSlidingSyncMigration = matrixClient.forceNativeSlidingSyncMigration().getOrDefault(false)
104+
forceNativeSlidingSyncMigration = matrixClient.needsForcedNativeSlidingSyncMigration().getOrDefault(false)
107105
}
108106
LoggedInEvents.LogoutAndMigrateToNativeSlidingSync -> coroutineScope.launch {
109-
// Enable native sliding sync if it wasn't already the case
110-
enableNativeSlidingSyncUseCase()
111-
// Then force the logout
107+
// Force the logout since Native Sliding Sync is already enforced by the SDK
112108
matrixClient.logout(userInitiated = true, ignoreSdkError = true)
113109
}
114110
}
@@ -123,16 +119,10 @@ class LoggedInPresenter @Inject constructor(
123119
)
124120
}
125121

126-
// Force the user to log out if they were using the proxy sliding sync and it's no longer available, but native sliding sync is.
127-
private suspend fun MatrixClient.forceNativeSlidingSyncMigration(): Result<Boolean> = runCatching {
122+
// Force the user to log out if they were using the proxy sliding sync as it's no longer supported by the SDK
123+
private suspend fun MatrixClient.needsForcedNativeSlidingSyncMigration(): Result<Boolean> = runCatching {
128124
val currentSlidingSyncVersion = currentSlidingSyncVersion().getOrThrow()
129-
if (currentSlidingSyncVersion == SlidingSyncVersion.Proxy) {
130-
val availableSlidingSyncVersions = availableSlidingSyncVersions().getOrThrow()
131-
availableSlidingSyncVersions.contains(SlidingSyncVersion.Native) &&
132-
!availableSlidingSyncVersions.contains(SlidingSyncVersion.Proxy)
133-
} else {
134-
false
135-
}
125+
currentSlidingSyncVersion == SlidingSyncVersion.Proxy
136126
}
137127

138128
private suspend fun ensurePusherIsRegistered(pusherRegistrationState: MutableState<AsyncData<Unit>>) {

appnav/src/test/kotlin/io/element/android/appnav/loggedin/LoggedInPresenterTest.kt

+2-32
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
3030
import io.element.android.libraries.matrix.test.roomlist.FakeRoomListService
3131
import io.element.android.libraries.matrix.test.sync.FakeSyncService
3232
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
33-
import io.element.android.libraries.preferences.api.store.EnableNativeSlidingSyncUseCase
34-
import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore
3533
import io.element.android.libraries.push.api.PushService
3634
import io.element.android.libraries.push.test.FakePushService
3735
import io.element.android.libraries.pushproviders.api.Distributor
@@ -46,7 +44,6 @@ import io.element.android.tests.testutils.lambda.lambdaError
4644
import io.element.android.tests.testutils.lambda.lambdaRecorder
4745
import io.element.android.tests.testutils.lambda.value
4846
import kotlinx.coroutines.ExperimentalCoroutinesApi
49-
import kotlinx.coroutines.flow.first
5047
import kotlinx.coroutines.test.TestScope
5148
import kotlinx.coroutines.test.advanceUntilIdle
5249
import kotlinx.coroutines.test.runTest
@@ -99,7 +96,6 @@ class LoggedInPresenterTest {
9996
sessionVerificationService = verificationService,
10097
analyticsService = analyticsService,
10198
encryptionService = encryptionService,
102-
enableNativeSlidingSyncUseCase = EnableNativeSlidingSyncUseCase(InMemoryAppPreferencesStore(), this),
10399
)
104100
moleculeFlow(RecompositionMode.Immediate) {
105101
presenter.present()
@@ -518,28 +514,9 @@ class LoggedInPresenterTest {
518514
}
519515
}
520516

521-
@Test
522-
fun `present - CheckSlidingSyncProxyAvailability will not force the migration if native sliding sync is not supported too`() = runTest {
523-
val matrixClient = FakeMatrixClient(
524-
currentSlidingSyncVersionLambda = { Result.success(SlidingSyncVersion.Proxy) },
525-
availableSlidingSyncVersionsLambda = { Result.success(emptyList()) },
526-
)
527-
val presenter = createLoggedInPresenter(matrixClient = matrixClient)
528-
moleculeFlow(RecompositionMode.Immediate) {
529-
presenter.present()
530-
}.test {
531-
val initialState = awaitItem()
532-
assertThat(initialState.forceNativeSlidingSyncMigration).isFalse()
533-
534-
initialState.eventSink(LoggedInEvents.CheckSlidingSyncProxyAvailability)
535-
536-
expectNoEvents()
537-
}
538-
}
539-
540517
@OptIn(ExperimentalCoroutinesApi::class)
541518
@Test
542-
fun `present - LogoutAndMigrateToNativeSlidingSync enables native sliding sync and logs out the user`() = runTest {
519+
fun `present - LogoutAndMigrateToNativeSlidingSync logs out the user`() = runTest {
543520
val logoutLambda = lambdaRecorder<Boolean, Boolean, String?> { userInitiated, ignoreSdkError ->
544521
assertThat(userInitiated).isTrue()
545522
assertThat(ignoreSdkError).isTrue()
@@ -548,21 +525,16 @@ class LoggedInPresenterTest {
548525
val matrixClient = FakeMatrixClient().apply {
549526
this.logoutLambda = logoutLambda
550527
}
551-
val appPreferencesStore = InMemoryAppPreferencesStore()
552-
val enableNativeSlidingSyncUseCase = EnableNativeSlidingSyncUseCase(appPreferencesStore, this)
553-
val presenter = createLoggedInPresenter(matrixClient = matrixClient, enableNativeSlidingSyncUseCase = enableNativeSlidingSyncUseCase)
528+
val presenter = createLoggedInPresenter(matrixClient = matrixClient)
554529
moleculeFlow(RecompositionMode.Immediate) {
555530
presenter.present()
556531
}.test {
557532
val initialState = awaitItem()
558533

559-
assertThat(appPreferencesStore.isSimplifiedSlidingSyncEnabledFlow().first()).isFalse()
560-
561534
initialState.eventSink(LoggedInEvents.LogoutAndMigrateToNativeSlidingSync)
562535

563536
advanceUntilIdle()
564537

565-
assertThat(appPreferencesStore.isSimplifiedSlidingSyncEnabledFlow().first()).isTrue()
566538
assertThat(logoutLambda.assertions().isCalledOnce())
567539
}
568540
}
@@ -579,7 +551,6 @@ class LoggedInPresenterTest {
579551
sessionVerificationService: SessionVerificationService = FakeSessionVerificationService(),
580552
encryptionService: EncryptionService = FakeEncryptionService(),
581553
pushService: PushService = FakePushService(),
582-
enableNativeSlidingSyncUseCase: EnableNativeSlidingSyncUseCase = EnableNativeSlidingSyncUseCase(InMemoryAppPreferencesStore(), this),
583554
matrixClient: MatrixClient = FakeMatrixClient(roomListService = roomListService),
584555
): LoggedInPresenter {
585556
return LoggedInPresenter(
@@ -589,7 +560,6 @@ class LoggedInPresenterTest {
589560
sessionVerificationService = sessionVerificationService,
590561
analyticsService = analyticsService,
591562
encryptionService = encryptionService,
592-
enableNativeSlidingSyncUseCase = enableNativeSlidingSyncUseCase,
593563
)
594564
}
595565
}

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsEvents.kt

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import io.element.android.libraries.featureflag.ui.model.FeatureUiModel
1313
sealed interface DeveloperSettingsEvents {
1414
data class UpdateEnabledFeature(val feature: FeatureUiModel, val isEnabled: Boolean) : DeveloperSettingsEvents
1515
data class SetCustomElementCallBaseUrl(val baseUrl: String?) : DeveloperSettingsEvents
16-
data class SetSimplifiedSlidingSyncEnabled(val isEnabled: Boolean) : DeveloperSettingsEvents
1716
data class SetHideImagesAndVideos(val value: Boolean) : DeveloperSettingsEvents
1817
data class SetTracingLogLevel(val logLevel: LogLevelItem) : DeveloperSettingsEvents
1918
data object ClearCache : DeveloperSettingsEvents

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenter.kt

-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import androidx.compose.runtime.remember
1919
import androidx.compose.runtime.rememberCoroutineScope
2020
import androidx.compose.runtime.snapshots.SnapshotStateMap
2121
import io.element.android.appconfig.ElementCallConfig
22-
import io.element.android.features.logout.api.LogoutUseCase
2322
import io.element.android.features.preferences.impl.developer.tracing.toLogLevel
2423
import io.element.android.features.preferences.impl.developer.tracing.toLogLevelItem
2524
import io.element.android.features.preferences.impl.tasks.ClearCacheUseCase
@@ -51,7 +50,6 @@ class DeveloperSettingsPresenter @Inject constructor(
5150
private val rageshakePresenter: Presenter<RageshakePreferencesState>,
5251
private val appPreferencesStore: AppPreferencesStore,
5352
private val buildMeta: BuildMeta,
54-
private val logoutUseCase: LogoutUseCase,
5553
) : Presenter<DeveloperSettingsState> {
5654
@Composable
5755
override fun present(): DeveloperSettingsState {
@@ -72,9 +70,6 @@ class DeveloperSettingsPresenter @Inject constructor(
7270
val customElementCallBaseUrl by appPreferencesStore
7371
.getCustomElementCallBaseUrlFlow()
7472
.collectAsState(initial = null)
75-
val isSimplifiedSlidingSyncEnabled by appPreferencesStore
76-
.isSimplifiedSlidingSyncEnabledFlow()
77-
.collectAsState(initial = false)
7873
val hideImagesAndVideos by appPreferencesStore
7974
.doesHideImagesAndVideosFlow()
8075
.collectAsState(initial = false)
@@ -122,12 +117,6 @@ class DeveloperSettingsPresenter @Inject constructor(
122117
appPreferencesStore.setCustomElementCallBaseUrl(urlToSave)
123118
}
124119
DeveloperSettingsEvents.ClearCache -> coroutineScope.clearCache(clearCacheAction)
125-
is DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled -> coroutineScope.launch {
126-
appPreferencesStore.setSimplifiedSlidingSyncEnabled(event.isEnabled)
127-
runCatching {
128-
logoutUseCase.logout(ignoreSdkError = true)
129-
}
130-
}
131120
is DeveloperSettingsEvents.SetHideImagesAndVideos -> coroutineScope.launch {
132121
appPreferencesStore.setHideImagesAndVideos(event.value)
133122
}
@@ -147,7 +136,6 @@ class DeveloperSettingsPresenter @Inject constructor(
147136
defaultUrl = ElementCallConfig.DEFAULT_BASE_URL,
148137
validator = ::customElementCallUrlValidator,
149138
),
150-
isSimpleSlidingSyncEnabled = isSimplifiedSlidingSyncEnabled,
151139
hideImagesAndVideos = hideImagesAndVideos,
152140
tracingLogLevel = tracingLogLevel,
153141
eventSink = ::handleEvents

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsState.kt

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ data class DeveloperSettingsState(
2020
val rageshakeState: RageshakePreferencesState,
2121
val clearCacheAction: AsyncAction<Unit>,
2222
val customElementCallBaseUrlState: CustomElementCallBaseUrlState,
23-
val isSimpleSlidingSyncEnabled: Boolean,
2423
val hideImagesAndVideos: Boolean,
2524
val tracingLogLevel: AsyncData<LogLevelItem>,
2625
val eventSink: (DeveloperSettingsEvents) -> Unit

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsStateProvider.kt

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ open class DeveloperSettingsStateProvider : PreviewParameterProvider<DeveloperSe
3232
fun aDeveloperSettingsState(
3333
clearCacheAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
3434
customElementCallBaseUrlState: CustomElementCallBaseUrlState = aCustomElementCallBaseUrlState(),
35-
isSimplifiedSlidingSyncEnabled: Boolean = false,
3635
hideImagesAndVideos: Boolean = false,
3736
eventSink: (DeveloperSettingsEvents) -> Unit = {},
3837
) = DeveloperSettingsState(
@@ -41,7 +40,6 @@ fun aDeveloperSettingsState(
4140
cacheSize = AsyncData.Success("1.2 MB"),
4241
clearCacheAction = clearCacheAction,
4342
customElementCallBaseUrlState = customElementCallBaseUrlState,
44-
isSimpleSlidingSyncEnabled = isSimplifiedSlidingSyncEnabled,
4543
hideImagesAndVideos = hideImagesAndVideos,
4644
tracingLogLevel = AsyncData.Success(LogLevelItem.INFO),
4745
eventSink = eventSink,

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsView.kt

-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ fun DeveloperSettingsView(
6060
state.eventSink(DeveloperSettingsEvents.SetTracingLogLevel(logLevel))
6161
}
6262
)
63-
PreferenceSwitch(
64-
title = "Enable Simplified Sliding Sync",
65-
subtitle = "When toggled you'll be logged out of the app and will need to log in again.",
66-
isChecked = state.isSimpleSlidingSyncEnabled,
67-
onCheckedChange = {
68-
state.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(it))
69-
}
70-
)
7163
}
7264
PreferenceCategory(title = "Showkase") {
7365
PreferenceText(

features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt

-34
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package io.element.android.features.preferences.impl.developer
1111

1212
import com.google.common.truth.Truth.assertThat
1313
import io.element.android.appconfig.ElementCallConfig
14-
import io.element.android.features.logout.test.FakeLogoutUseCase
1514
import io.element.android.features.preferences.impl.developer.tracing.LogLevelItem
1615
import io.element.android.features.preferences.impl.tasks.FakeClearCacheUseCase
1716
import io.element.android.features.preferences.impl.tasks.FakeComputeCacheSizeUseCase
@@ -25,11 +24,9 @@ import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
2524
import io.element.android.libraries.matrix.test.core.aBuildMeta
2625
import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore
2726
import io.element.android.tests.testutils.WarmUpRule
28-
import io.element.android.tests.testutils.lambda.lambdaRecorder
2927
import io.element.android.tests.testutils.test
3028
import kotlinx.coroutines.ExperimentalCoroutinesApi
3129
import kotlinx.coroutines.flow.first
32-
import kotlinx.coroutines.test.advanceUntilIdle
3330
import kotlinx.coroutines.test.runTest
3431
import org.junit.Rule
3532
import org.junit.Test
@@ -48,7 +45,6 @@ class DeveloperSettingsPresenterTest {
4845
assertThat(state.cacheSize).isEqualTo(AsyncData.Uninitialized)
4946
assertThat(state.customElementCallBaseUrlState).isNotNull()
5047
assertThat(state.customElementCallBaseUrlState.baseUrl).isNull()
51-
assertThat(state.isSimpleSlidingSyncEnabled).isFalse()
5248
assertThat(state.hideImagesAndVideos).isFalse()
5349
assertThat(state.rageshakeState.isEnabled).isFalse()
5450
assertThat(state.rageshakeState.isSupported).isTrue()
@@ -153,34 +149,6 @@ class DeveloperSettingsPresenterTest {
153149
}
154150
}
155151

156-
@Test
157-
fun `present - toggling simplified sliding sync changes the preferences and logs out the user`() = runTest {
158-
val logoutCallRecorder = lambdaRecorder<Boolean, String?> { "" }
159-
val logoutUseCase = FakeLogoutUseCase(logoutLambda = logoutCallRecorder)
160-
val preferences = InMemoryAppPreferencesStore()
161-
val presenter = createDeveloperSettingsPresenter(preferencesStore = preferences, logoutUseCase = logoutUseCase)
162-
presenter.test {
163-
skipItems(2)
164-
awaitItem().also { state ->
165-
assertThat(state.isSimpleSlidingSyncEnabled).isFalse()
166-
state.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(true))
167-
}
168-
awaitItem().also { state ->
169-
assertThat(state.isSimpleSlidingSyncEnabled).isTrue()
170-
assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isTrue()
171-
advanceUntilIdle()
172-
logoutCallRecorder.assertions().isCalledOnce()
173-
state.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(false))
174-
}
175-
awaitItem().also { state ->
176-
assertThat(state.isSimpleSlidingSyncEnabled).isFalse()
177-
assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isFalse()
178-
advanceUntilIdle()
179-
logoutCallRecorder.assertions().isCalledExactly(2)
180-
}
181-
}
182-
}
183-
184152
@Test
185153
fun `present - toggling hide image and video`() = runTest {
186154
val preferences = InMemoryAppPreferencesStore()
@@ -225,7 +193,6 @@ class DeveloperSettingsPresenterTest {
225193
clearCacheUseCase: FakeClearCacheUseCase = FakeClearCacheUseCase(),
226194
preferencesStore: InMemoryAppPreferencesStore = InMemoryAppPreferencesStore(),
227195
buildMeta: BuildMeta = aBuildMeta(),
228-
logoutUseCase: FakeLogoutUseCase = FakeLogoutUseCase(logoutLambda = { "" })
229196
): DeveloperSettingsPresenter {
230197
return DeveloperSettingsPresenter(
231198
featureFlagService = featureFlagService,
@@ -234,7 +201,6 @@ class DeveloperSettingsPresenterTest {
234201
rageshakePresenter = { aRageshakePreferencesState() },
235202
appPreferencesStore = preferencesStore,
236203
buildMeta = buildMeta,
237-
logoutUseCase = logoutUseCase,
238204
)
239205
}
240206
}

features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsViewTest.kt

-13
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,6 @@ class DeveloperSettingsViewTest {
102102
eventsRecorder.assertSingle(DeveloperSettingsEvents.ClearCache)
103103
}
104104

105-
@Config(qualifiers = "h1500dp")
106-
@Test
107-
fun `clicking on the simplified sliding sync switch emits the expected event`() {
108-
val eventsRecorder = EventsRecorder<DeveloperSettingsEvents>()
109-
rule.setDeveloperSettingsView(
110-
state = aDeveloperSettingsState(
111-
eventSink = eventsRecorder
112-
),
113-
)
114-
rule.onNodeWithText("Enable Simplified Sliding Sync").performClick()
115-
eventsRecorder.assertSingle(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(true))
116-
}
117-
118105
@Test
119106
fun `clicking on the hide images and videos switch emits the expected event`() {
120107
val eventsRecorder = EventsRecorder<DeveloperSettingsEvents>()

features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContentStateProvider.kt

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ open class RoomListContentStateProvider : PreviewParameterProvider<RoomListConte
2222
aSkeletonContentState(),
2323
anEmptyContentState(),
2424
anEmptyContentState(securityBannerState = SecurityBannerState.SetUpRecovery),
25-
aRoomsContentState(securityBannerState = SecurityBannerState.NeedsNativeSlidingSyncMigration),
2625
)
2726
}
2827

0 commit comments

Comments
 (0)