Skip to content

Commit

Permalink
Fixes #3231 - Rewrite how out of band verification changes are handle…
Browse files Browse the repository at this point in the history
…d within the onboarding flows
  • Loading branch information
stefanceriu committed Sep 6, 2024
1 parent b43797f commit 2da4059
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
actionsSubject.eraseToAnyPublisher()
}

private var verificationStateCancellable: AnyCancellable?

init(userSession: UserSessionProtocol,
appLockService: AppLockServiceProtocol,
analyticsService: AnalyticsService,
Expand All @@ -83,6 +85,21 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
self.navigationStackCoordinator = NavigationStackCoordinator()

stateMachine = .init(state: .initial)

// Always react to verification changes, not only when freshly
// verified from
verificationStateCancellable = userSession.sessionSecurityStatePublisher
.map(\.verificationState)
.removeDuplicates()
.sink { [weak self] value in
guard let self,
value == .verified,
stateMachine.state == .identityConfirmation else { return }

appSettings.hasRunIdentityConfirmationOnboarding = true
stateMachine.tryEvent(.nextSkippingIdentityConfimed)
self.verificationStateCancellable = nil
}
}

var shouldStart: Bool {
Expand Down Expand Up @@ -249,27 +266,7 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
}
.store(in: &cancellables)

// If the verification state is still unknown wait for it to resolve
// and just move on to the next steps if verified
var verificationStateCancellable: AnyCancellable?
if userSession.sessionSecurityStatePublisher.value.verificationState == .unknown {
verificationStateCancellable = userSession.sessionSecurityStatePublisher
.map(\.verificationState)
.removeDuplicates()
.sink { [weak self] value in
guard let self else { return }

if value == .verified {
appSettings.hasRunIdentityConfirmationOnboarding = true
stateMachine.tryEvent(.nextSkippingIdentityConfimed)
verificationStateCancellable?.cancel()
}
}
}

presentCoordinator(coordinator) { [verificationStateCancellable] in
verificationStateCancellable?.cancel()
}
presentCoordinator(coordinator)
}

private func presentSessionVerificationScreen() async {
Expand All @@ -287,8 +284,7 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {

switch action {
case .done:
appSettings.hasRunIdentityConfirmationOnboarding = true
stateMachine.tryEvent(.next)
break // Moving to next state is handled by the global session verification listener
}
}
.store(in: &cancellables)
Expand All @@ -309,8 +305,7 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {

switch action {
case .recoveryFixed:
appSettings.hasRunIdentityConfirmationOnboarding = true
stateMachine.tryEvent(.next)
break // Moving to next state is Handled by the global session verification listener
case .resetEncryption:
presentEncryptionResetScreen()
default:
Expand Down Expand Up @@ -338,8 +333,7 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol {
case .requestOIDCAuthorisation(let url):
presentOIDCAuthorisationScreen(url: url)
case .resetFinished:
appSettings.hasRunIdentityConfirmationOnboarding = true
stateMachine.tryEvent(.next)
// Moving to next state is handled by the global session verification listener
navigationStackCoordinator.setSheetCoordinator(nil)
}
}
Expand Down

0 comments on commit 2da4059

Please sign in to comment.