Soft logout removal (#672)

* Remove isSoftLogout from everywhere except the client delegate
- bump the RustSDK to v1.0.43
- cleanup the app coordinator state machine and login/logout flows

* Merge `succeededSigningIn` and `succeededRestoringSession` into `createdUserSession` in order to simplify the logic
This commit is contained in:
Stefan Ceriu
2023-03-06 14:58:50 +02:00
committed by GitHub
parent 1fe2e7e882
commit e4117e3205
13 changed files with 34 additions and 122 deletions
@@ -154,7 +154,6 @@ class AppCoordinator: AppCoordinatorProtocol {
userSessionStore.reset()
}
// swiftlint:disable:next cyclomatic_complexity
private func setupStateMachine() {
stateMachine.addTransitionHandler { [weak self] context in
guard let self else { return }
@@ -162,25 +161,19 @@ class AppCoordinator: AppCoordinatorProtocol {
switch (context.fromState, context.event, context.toState) {
case (.initial, .startWithAuthentication, .signedOut):
self.startAuthentication()
case (.signedOut, .succeededSigningIn, .signedIn):
case (.signedOut, .createdUserSession, .signedIn):
self.setupUserSession()
case (.initial, .startWithExistingSession, .restoringSession):
self.restoreUserSession()
case (.restoringSession, .failedRestoringSession, .signedOut):
self.showLoginErrorToast()
self.presentSplashScreen()
case (.restoringSession, .succeededRestoringSession, .signedIn):
case (.restoringSession, .createdUserSession, .signedIn):
self.setupUserSession()
case (_, .signOut, .signingOut):
self.logout(isSoftLogout: false)
case (.signingOut, .completedSigningOut, .signedOut):
self.tearDownUserSession()
self.presentSplashScreen()
case (_, .remoteSignOut(let isSoftLogout), .remoteSigningOut):
self.logout(isSoftLogout: isSoftLogout)
case (.remoteSigningOut(let isSoftLogout), .completedSigningOut, .signedOut):
self.tearDownUserSession()
self.presentSplashScreen(isSoftLogout: isSoftLogout)
case (_, .signOut(let isSoft), .signingOut):
self.logout(isSoft: isSoft)
case (.signingOut, .completedSigningOut(let isSoft), .signedOut):
self.presentSplashScreen(isSoftLogout: isSoft)
default:
fatalError("Unknown transition: \(context)")
}
@@ -196,11 +189,7 @@ class AppCoordinator: AppCoordinatorProtocol {
switch await userSessionStore.restoreUserSession() {
case .success(let userSession):
self.userSession = userSession
if userSession.isSoftLogout {
stateMachine.processEvent(.remoteSignOut(isSoft: true))
} else {
stateMachine.processEvent(.succeededRestoringSession)
}
stateMachine.processEvent(.createdUserSession)
case .failure:
MXLog.error("Failed to restore an existing session.")
stateMachine.processEvent(.failedRestoringSession)
@@ -243,12 +232,9 @@ class AppCoordinator: AppCoordinatorProtocol {
switch result {
case .signedIn(let session):
self.userSession = session
self.stateMachine.processEvent(.succeededSigningIn)
self.stateMachine.processEvent(.createdUserSession)
case .clearAllData:
// clear user data
self.userSessionStore.logout(userSession: self.userSession)
self.userSession = nil
self.startAuthentication()
self.stateMachine.processEvent(.signOut(isSoft: false))
}
}
@@ -266,7 +252,7 @@ class AppCoordinator: AppCoordinatorProtocol {
userSessionFlowCoordinator.callback = { [weak self] action in
switch action {
case .signOut:
self?.stateMachine.processEvent(.signOut)
self?.stateMachine.processEvent(.signOut(isSoft: false))
}
}
@@ -277,7 +263,7 @@ class AppCoordinator: AppCoordinatorProtocol {
navigationRootCoordinator.setRootCoordinator(navigationSplitCoordinator)
}
private func logout(isSoftLogout: Bool) {
private func logout(isSoft: Bool) {
showLoadingIndicator()
defer {
@@ -287,8 +273,8 @@ class AppCoordinator: AppCoordinatorProtocol {
userSession.clientProxy.stopSync()
userSessionFlowCoordinator?.stop()
guard !isSoftLogout else {
stateMachine.processEvent(.completedSigningOut)
guard !isSoft else {
stateMachine.processEvent(.completedSigningOut(isSoft: isSoft))
return
}
@@ -298,8 +284,9 @@ class AppCoordinator: AppCoordinatorProtocol {
// regardless of the result, clear user data
userSessionStore.logout(userSession: userSession)
tearDownUserSession()
stateMachine.processEvent(.completedSigningOut)
stateMachine.processEvent(.completedSigningOut(isSoft: isSoft))
}
}
@@ -361,11 +348,7 @@ class AppCoordinator: AppCoordinatorProtocol {
guard let self else { return }
switch callback {
case .didReceiveAuthError(let isSoftLogout):
self.stateMachine.processEvent(.remoteSignOut(isSoft: isSoftLogout))
case .updateRestoreTokenNeeded:
if let userSession = self.userSession {
_ = self.userSessionStore.refreshRestorationToken(for: userSession)
}
self.stateMachine.processEvent(.signOut(isSoft: isSoftLogout))
default:
break
}
@@ -463,7 +446,7 @@ class AppCoordinator: AppCoordinatorProtocol {
extension AppCoordinator: AuthenticationCoordinatorDelegate {
func authenticationCoordinator(_ authenticationCoordinator: AuthenticationCoordinator, didLoginWithSession userSession: UserSessionProtocol) {
self.userSession = userSession
stateMachine.processEvent(.succeededSigningIn)
stateMachine.processEvent(.createdUserSession)
}
}
@@ -31,32 +31,27 @@ class AppCoordinatorStateMachine {
case signedIn
/// Processing a sign out request
case signingOut
/// Processing a remote sign out
case remoteSigningOut(isSoft: Bool)
case signingOut(isSoft: Bool)
}
/// Events that can be triggered on the AppCoordinator state machine
enum Event: EventType {
/// Start the `AppCoordinator` by showing authentication.
case startWithAuthentication
/// Signing in succeeded
case succeededSigningIn
/// Start the `AppCoordinator` by restoring an existing account.
case startWithExistingSession
/// Restoring session succeeded.
case succeededRestoringSession
/// Restoring session failed.
case failedRestoringSession
/// A session has been created
case createdUserSession
/// Request sign out
case signOut
/// Remote sign out.
case remoteSignOut(isSoft: Bool)
case signOut(isSoft: Bool)
/// Signing out completed
case completedSigningOut
case completedSigningOut(isSoft: Bool)
}
private let stateMachine: StateMachine<State, Event>
@@ -72,21 +67,18 @@ class AppCoordinatorStateMachine {
private func configure() {
stateMachine.addRoutes(event: .startWithAuthentication, transitions: [.initial => .signedOut])
stateMachine.addRoutes(event: .succeededSigningIn, transitions: [.signedOut => .signedIn])
stateMachine.addRoutes(event: .createdUserSession, transitions: [.signedOut => .signedIn])
stateMachine.addRoutes(event: .startWithExistingSession, transitions: [.initial => .restoringSession])
stateMachine.addRoutes(event: .succeededRestoringSession, transitions: [.restoringSession => .signedIn])
stateMachine.addRoutes(event: .createdUserSession, transitions: [.restoringSession => .signedIn])
stateMachine.addRoutes(event: .failedRestoringSession, transitions: [.restoringSession => .signedOut])
stateMachine.addRoutes(event: .signOut, transitions: [.any => .signingOut])
stateMachine.addRoutes(event: .completedSigningOut, transitions: [.signingOut => .signedOut])
// Transitions with associated values need to be handled through `addRouteMapping`
stateMachine.addRouteMapping { event, fromState, _ in
switch (event, fromState) {
case (.remoteSignOut(let isSoft), _):
return .remoteSigningOut(isSoft: isSoft)
case (.completedSigningOut, .remoteSigningOut):
case (.signOut(let isSoft), _):
return .signingOut(isSoft: isSoft)
case (.completedSigningOut, .signingOut):
return .signedOut
default:
return nil