Don't reset the SSS toggle when logged out.

Instead, force a logout when toggling the option so user needs to log in again and create a new session using SSS.
This commit is contained in:
Jorge Martín 2024-07-19 16:32:25 +02:00
parent 114b12cbc7
commit ff6ea43237
7 changed files with 81 additions and 7 deletions

View file

@ -28,6 +28,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshots.SnapshotStateMap
import io.element.android.appconfig.ElementCallConfig
import io.element.android.features.logout.api.LogoutUseCase
import io.element.android.features.preferences.impl.tasks.ClearCacheUseCase
import io.element.android.features.preferences.impl.tasks.ComputeCacheSizeUseCase
import io.element.android.features.rageshake.api.preferences.RageshakePreferencesPresenter
@ -55,6 +56,7 @@ class DeveloperSettingsPresenter @Inject constructor(
private val rageshakePresenter: RageshakePreferencesPresenter,
private val appPreferencesStore: AppPreferencesStore,
private val buildMeta: BuildMeta,
private val logoutUseCase: LogoutUseCase,
) : Presenter<DeveloperSettingsState> {
@Composable
override fun present(): DeveloperSettingsState {
@ -119,6 +121,7 @@ class DeveloperSettingsPresenter @Inject constructor(
DeveloperSettingsEvents.ClearCache -> coroutineScope.clearCache(clearCacheAction)
is DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled -> coroutineScope.launch {
appPreferencesStore.setSimplifiedSlidingSyncEnabled(event.isEnabled)
logoutUseCase.logout(ignoreSdkError = true)
}
}
}

View file

@ -63,7 +63,7 @@ fun DeveloperSettingsView(
)
PreferenceSwitch(
title = "Enable Simplified Sliding Sync",
subtitle = "This option requires an app restart to work.",
subtitle = "When toggled you'll be logged out of the app and will need to log in again.",
isChecked = state.isSimpleSlidingSyncEnabled,
onCheckedChange = {
state.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(it))

View file

@ -21,6 +21,7 @@ import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.appconfig.ElementCallConfig
import io.element.android.features.logout.api.LogoutUseCase
import io.element.android.features.preferences.impl.tasks.FakeClearCacheUseCase
import io.element.android.features.preferences.impl.tasks.FakeComputeCacheSizeUseCase
import io.element.android.features.rageshake.impl.preferences.DefaultRageshakePreferencesPresenter
@ -163,9 +164,10 @@ class DeveloperSettingsPresenterTest {
}
@Test
fun `present - toggling simplified sliding sync changes the preferences`() = runTest {
fun `present - toggling simplified sliding sync changes the preferences and logs out the user`() = runTest {
val logoutUseCase = FakeLogoutUseCase()
val preferences = InMemoryAppPreferencesStore()
val presenter = createDeveloperSettingsPresenter(preferencesStore = preferences)
val presenter = createDeveloperSettingsPresenter(preferencesStore = preferences, logoutUseCase = logoutUseCase)
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
@ -175,10 +177,12 @@ class DeveloperSettingsPresenterTest {
initialState.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(true))
assertThat(awaitItem().isSimpleSlidingSyncEnabled).isTrue()
assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isTrue()
assertThat(logoutUseCase.logoutCallCount).isEqualTo(1)
initialState.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(false))
assertThat(awaitItem().isSimpleSlidingSyncEnabled).isFalse()
assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isFalse()
assertThat(logoutUseCase.logoutCallCount).isEqualTo(2)
}
}
@ -189,6 +193,7 @@ class DeveloperSettingsPresenterTest {
rageshakePresenter: DefaultRageshakePreferencesPresenter = DefaultRageshakePreferencesPresenter(FakeRageShake(), FakeRageshakeDataStore()),
preferencesStore: InMemoryAppPreferencesStore = InMemoryAppPreferencesStore(),
buildMeta: BuildMeta = aBuildMeta(),
logoutUseCase: FakeLogoutUseCase = FakeLogoutUseCase()
): DeveloperSettingsPresenter {
return DeveloperSettingsPresenter(
featureFlagService = featureFlagService,
@ -197,6 +202,16 @@ class DeveloperSettingsPresenterTest {
rageshakePresenter = rageshakePresenter,
appPreferencesStore = preferencesStore,
buildMeta = buildMeta,
logoutUseCase = logoutUseCase,
)
}
}
private class FakeLogoutUseCase : LogoutUseCase {
var logoutCallCount = 0
private set
override suspend fun logout(ignoreSdkError: Boolean) {
logoutCallCount++
}
}