Skip to content

Commit

Permalink
Automatically sign out when toggling the SSS feature flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jul 19, 2024
1 parent 74907d3 commit d8ee2a6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ final class AppSettings {
static func resetSessionSpecificSettings() {
MXLog.warning("Resetting the user session specific AppSettings.")
store.removeObject(forKey: UserDefaultsKeys.hasRunIdentityConfirmationOnboarding.rawValue)
store.removeObject(forKey: UserDefaultsKeys.simplifiedSlidingSyncEnabled.rawValue)
}

static func configureWithSuiteName(_ name: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {
switch action {
case .clearCache:
actionsSubject.send(.clearCache)
case .forceLogout:
actionsSubject.send(.forceLogout)
}
}
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import SwiftUI

enum DeveloperOptionsScreenCoordinatorAction {
case clearCache
/// Logout without a confirmation to avoid losing keys when trying SSS.
case forceLogout
}

final class DeveloperOptionsScreenCoordinator: CoordinatorProtocol {
Expand All @@ -42,6 +44,8 @@ final class DeveloperOptionsScreenCoordinator: CoordinatorProtocol {
switch action {
case .clearCache:
actionsSubject.send(.clearCache)
case .forceLogout:
actionsSubject.send(.forceLogout)
}
}
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Foundation

enum DeveloperOptionsScreenViewModelAction {
case clearCache
/// Logout without a confirmation to avoid losing keys when trying SSS.
case forceLogout
}

struct DeveloperOptionsScreenViewState: BindableState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class DeveloperOptionsScreenViewModel: DeveloperOptionsScreenViewModelType, Deve
let state = DeveloperOptionsScreenViewState(elementCallBaseURL: elementCallBaseURL, bindings: bindings)

super.init(initialViewState: state)

context.$viewState
.map(\.bindings.simplifiedSlidingSyncEnabled)
.removeDuplicates()
.dropFirst() // Ignore the initial value received when opening the screen.
.sink { [weak self] isEnabled in
MXLog.error("Toggled simplifiedSlidingSyncEnabled: \(isEnabled). Signing out.")
self?.actionsSubject.send(.forceLogout)
}
.store(in: &cancellables)
}

override func process(viewAction: DeveloperOptionsScreenViewAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct DeveloperOptionsScreen: View {
Section("Sliding Sync") {
Toggle(isOn: $context.simplifiedSlidingSyncEnabled) {
Text("Simplified Sliding Sync")
Text("Requires app reboot")
Text("When toggled you'll be logged out of the app and will need to log in again.")
}
}

Expand Down

0 comments on commit d8ee2a6

Please sign in to comment.