Skip to content

Commit

Permalink
Add a logout option on the root of IdentityVerification screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Aug 30, 2024
1 parent 904045f commit 32e1e1a
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 15 deletions.
11 changes: 11 additions & 0 deletions ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import Combine
import Foundation
import SwiftState

enum OnboardingFlowCoordinatorAction {
case logout
}

class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
private let userSession: UserSessionProtocol
private let appLockService: AppLockServiceProtocol
Expand Down Expand Up @@ -52,6 +56,11 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
// periphery: ignore - used to store the coordinator to avoid deallocation
private var appLockFlowCoordinator: AppLockSetupFlowCoordinator?

private let actionsSubject: PassthroughSubject<OnboardingFlowCoordinatorAction, Never> = .init()
var actions: AnyPublisher<OnboardingFlowCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}

init(userSession: UserSessionProtocol,
appLockService: AppLockServiceProtocol,
analyticsService: AnalyticsService,
Expand Down Expand Up @@ -234,6 +243,8 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
stateMachine.tryEvent(.nextSkippingIdentityConfimed)
case .reset:
presentEncryptionResetScreen()
case .logout:
actionsSubject.send(.logout)
}
}
.store(in: &cancellables)
Expand Down
27 changes: 21 additions & 6 deletions ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
}
}
.store(in: &cancellables)

onboardingFlowCoordinator.actions
.sink { [weak self] action in
guard let self else { return }

switch action {
case .logout:
logout()
}
}
.store(in: &cancellables)
}

func start() {
Expand Down Expand Up @@ -429,12 +440,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
}

guard isLastDevice else {
ServiceLocator.shared.userIndicatorController.alertInfo = .init(id: .init(),
title: L10n.screenSignoutConfirmationDialogTitle,
message: L10n.screenSignoutConfirmationDialogContent,
primaryButton: .init(title: L10n.screenSignoutConfirmationDialogSubmit, role: .destructive) { [weak self] in
self?.actionsSubject.send(.logout)
})
logout()
return
}

Expand Down Expand Up @@ -465,6 +471,15 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
presentSecureBackupLogoutConfirmationScreen()
}

private func logout() {
ServiceLocator.shared.userIndicatorController.alertInfo = .init(id: .init(),
title: L10n.screenSignoutConfirmationDialogTitle,
message: L10n.screenSignoutConfirmationDialogContent,
primaryButton: .init(title: L10n.screenSignoutConfirmationDialogSubmit, role: .destructive) { [weak self] in
self?.actionsSubject.send(.logout)
})
}

// MARK: Room Flow

private func startRoomFlow(roomID: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum IdentityConfirmationScreenCoordinatorAction {
/// Only possible in debug builds.
case skip
case reset
case logout
}

final class IdentityConfirmationScreenCoordinator: CoordinatorProtocol {
Expand Down Expand Up @@ -64,6 +65,8 @@ final class IdentityConfirmationScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.skip)
case .reset:
actionsSubject.send(.reset)
case .logout:
actionsSubject.send(.logout)
}
}
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum IdentityConfirmationScreenViewModelAction {
/// Only possible in debug builds.
case skip
case reset
case logout
}

struct IdentityConfirmationScreenViewState: BindableState {
Expand All @@ -40,4 +41,5 @@ enum IdentityConfirmationScreenViewAction {
/// Only possible in debug builds.
case skip
case reset
case logout
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class IdentityConfirmationScreenViewModel: IdentityConfirmationScreenViewModelTy
actionsSubject.send(.skip)
case .reset:
actionsSubject.send(.reset)
case .logout:
actionsSubject.send(.logout)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ struct IdentityConfirmationScreen: View {
} bottomContent: {
actionButtons
}
.toolbar { toolbar }
.background()
.backgroundStyle(.compound.bgCanvasDefault)
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
.interactiveDismissDisabled()
}
Expand Down Expand Up @@ -104,6 +104,15 @@ struct IdentityConfirmationScreen: View {
.padding(.vertical, 14)
}
}

@ToolbarContentBuilder
var toolbar: some ToolbarContent {
ToolbarItem(placement: .destructiveAction) {
Button(L10n.actionSignout) {
context.send(viewAction: .logout)
}
}
}
}

// MARK: - Previews
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 32e1e1a

Please sign in to comment.