Add a logout option on the root of IdentityVerification screen.

This commit is contained in:
Stefan Ceriu 2024-08-29 14:39:08 +03:00 committed by Stefan Ceriu
parent 904045f178
commit 32e1e1aa24
10 changed files with 57 additions and 15 deletions

View File

@ -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
@ -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,
@ -234,6 +243,8 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
stateMachine.tryEvent(.nextSkippingIdentityConfimed)
case .reset:
presentEncryptionResetScreen()
case .logout:
actionsSubject.send(.logout)
}
}
.store(in: &cancellables)

View File

@ -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() {
@ -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
}
@ -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,

View File

@ -29,6 +29,7 @@ enum IdentityConfirmationScreenCoordinatorAction {
/// Only possible in debug builds.
case skip
case reset
case logout
}
final class IdentityConfirmationScreenCoordinator: CoordinatorProtocol {
@ -64,6 +65,8 @@ final class IdentityConfirmationScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.skip)
case .reset:
actionsSubject.send(.reset)
case .logout:
actionsSubject.send(.logout)
}
}
.store(in: &cancellables)

View File

@ -22,6 +22,7 @@ enum IdentityConfirmationScreenViewModelAction {
/// Only possible in debug builds.
case skip
case reset
case logout
}
struct IdentityConfirmationScreenViewState: BindableState {
@ -40,4 +41,5 @@ enum IdentityConfirmationScreenViewAction {
/// Only possible in debug builds.
case skip
case reset
case logout
}

View File

@ -61,6 +61,8 @@ class IdentityConfirmationScreenViewModel: IdentityConfirmationScreenViewModelTy
actionsSubject.send(.skip)
case .reset:
actionsSubject.send(.reset)
case .logout:
actionsSubject.send(.logout)
}
}

View File

@ -34,9 +34,9 @@ struct IdentityConfirmationScreen: View {
} bottomContent: {
actionButtons
}
.toolbar { toolbar }
.background()
.backgroundStyle(.compound.bgCanvasDefault)
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
.interactiveDismissDisabled()
}
@ -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