mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 03:48:27 +00:00
Automatically sign out when toggling the SSS feature flag. (#3071)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -233,6 +233,8 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {
|
||||
switch action {
|
||||
case .clearCache:
|
||||
actionsSubject.send(.clearCache)
|
||||
case .forceLogout:
|
||||
actionsSubject.send(.forceLogout)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -21,15 +21,20 @@ extension ClientBuilder {
|
||||
/// A helper method that applies the common builder modifiers needed for the app.
|
||||
static func baseBuilder(setupEncryption: Bool = true,
|
||||
httpProxy: String? = nil,
|
||||
slidingSync: ClientBuilderSlidingSync,
|
||||
slidingSyncProxy: URL? = nil,
|
||||
sessionDelegate: ClientSessionDelegate,
|
||||
simplifiedSlidingSyncEnabled: Bool,
|
||||
appHooks: AppHooks) -> ClientBuilder {
|
||||
var builder = ClientBuilder()
|
||||
.slidingSyncProxy(slidingSyncProxy: slidingSyncProxy?.absoluteString)
|
||||
.enableCrossProcessRefreshLock(processId: InfoPlistReader.main.bundleIdentifier, sessionDelegate: sessionDelegate)
|
||||
.userAgent(userAgent: UserAgentBuilder.makeASCIIUserAgent())
|
||||
.simplifiedSlidingSync(enable: simplifiedSlidingSyncEnabled)
|
||||
|
||||
builder = switch slidingSync {
|
||||
case .restored: builder
|
||||
case .discovered: builder.requiresSlidingSync()
|
||||
case .simplified: builder.simplifiedSlidingSync(enable: true)
|
||||
}
|
||||
|
||||
if setupEncryption {
|
||||
builder = builder
|
||||
@@ -45,3 +50,12 @@ extension ClientBuilder {
|
||||
return appHooks.clientBuilderHook.configure(builder)
|
||||
}
|
||||
}
|
||||
|
||||
enum ClientBuilderSlidingSync {
|
||||
/// The proxy will be supplied when restoring the Session.
|
||||
case restored
|
||||
/// A proxy must be discovered whilst building the session.
|
||||
case discovered
|
||||
/// Use Simplified Sliding Sync (discovery isn't a thing yet).
|
||||
case simplified
|
||||
}
|
||||
|
||||
+4
@@ -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 {
|
||||
@@ -42,6 +44,8 @@ final class DeveloperOptionsScreenCoordinator: CoordinatorProtocol {
|
||||
switch action {
|
||||
case .clearCache:
|
||||
actionsSubject.send(.clearCache)
|
||||
case .forceLogout:
|
||||
actionsSubject.send(.forceLogout)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
+2
@@ -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 {
|
||||
|
||||
+10
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,13 +141,12 @@ class AuthenticationService: AuthenticationServiceProtocol {
|
||||
private func makeClientBuilder() -> ClientBuilder {
|
||||
ClientBuilder
|
||||
.baseBuilder(httpProxy: appSettings.websiteURL.globalProxy,
|
||||
slidingSync: appSettings.simplifiedSlidingSyncEnabled ? .simplified : .discovered,
|
||||
slidingSyncProxy: appSettings.slidingSyncProxyURL,
|
||||
sessionDelegate: userSessionStore.clientSessionDelegate,
|
||||
simplifiedSlidingSyncEnabled: appSettings.simplifiedSlidingSyncEnabled,
|
||||
appHooks: appHooks)
|
||||
.sessionPath(path: sessionDirectory.path(percentEncoded: false))
|
||||
.passphrase(passphrase: passphrase)
|
||||
.requiresSlidingSync()
|
||||
}
|
||||
|
||||
private func userSession(for client: Client) async -> Result<UserSessionProtocol, AuthenticationServiceError> {
|
||||
|
||||
@@ -59,13 +59,12 @@ final class QRCodeLoginService: QRCodeLoginServiceProtocol {
|
||||
do {
|
||||
let client = try await ClientBuilder
|
||||
.baseBuilder(httpProxy: appSettings.websiteURL.globalProxy,
|
||||
slidingSync: appSettings.simplifiedSlidingSyncEnabled ? .simplified : .discovered,
|
||||
slidingSyncProxy: appSettings.slidingSyncProxyURL,
|
||||
sessionDelegate: userSessionStore.clientSessionDelegate,
|
||||
simplifiedSlidingSyncEnabled: appSettings.simplifiedSlidingSyncEnabled,
|
||||
appHooks: appHooks)
|
||||
.sessionPath(path: sessionDirectory.path(percentEncoded: false))
|
||||
.passphrase(passphrase: passphrase)
|
||||
.requiresSlidingSync()
|
||||
.buildWithQrCode(qrCodeData: qrData, oidcConfiguration: appSettings.oidcConfiguration.rustValue, progressListener: listener)
|
||||
return await login(client: client)
|
||||
} catch let error as HumanQrLoginError {
|
||||
|
||||
@@ -124,8 +124,8 @@ class UserSessionStore: UserSessionStoreProtocol {
|
||||
|
||||
let builder = ClientBuilder
|
||||
.baseBuilder(httpProxy: URL(string: homeserverURL)?.globalProxy,
|
||||
slidingSync: appSettings.simplifiedSlidingSyncEnabled ? .simplified : .restored,
|
||||
sessionDelegate: keychainController,
|
||||
simplifiedSlidingSyncEnabled: appSettings.simplifiedSlidingSyncEnabled,
|
||||
appHooks: appHooks)
|
||||
.sessionPath(path: credentials.restorationToken.sessionDirectory.path(percentEncoded: false))
|
||||
.username(username: credentials.userID)
|
||||
|
||||
Reference in New Issue
Block a user