Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly show Recovery Key and Encryption Reset screens from the home screen banner. #3482

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
// periphery:ignore - retaining purpose
private var bugReportFlowCoordinator: BugReportFlowCoordinator?

// periphery:ignore - retaining purpose
private var encryptionResetFlowCoordinator: EncryptionResetFlowCoordinator?

// periphery:ignore - retaining purpose
private var globalSearchScreenCoordinator: GlobalSearchScreenCoordinator?

Expand Down Expand Up @@ -263,6 +266,16 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
case (.feedbackScreen, .dismissedFeedbackScreen, .roomList):
break

case (.roomList, .showRecoveryKeyScreen, .recoveryKeyScreen):
presentRecoveryKeyScreen(animated: animated)
case (.recoveryKeyScreen, .dismissedRecoveryKeyScreen, .roomList):
break

case (.roomList, .startEncryptionResetFlow, .encryptionResetFlow):
startEncryptionResetFlow(animated: animated)
case (.encryptionResetFlow, .finishedEncryptionResetFlow, .roomList):
break

case (.roomList, .showStartChatScreen, .startChatScreen):
presentStartChat(animated: animated)
case (.startChatScreen, .dismissedStartChatScreen, .roomList):
Expand Down Expand Up @@ -453,8 +466,10 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
settingsFlowCoordinator.handleAppRoute(.settings, animated: true)
case .presentFeedbackScreen:
stateMachine.processEvent(.feedbackScreen)
case .presentSecureBackupSettings:
settingsFlowCoordinator.handleAppRoute(.chatBackupSettings, animated: true)
case .presentRecoveryKeyScreen:
stateMachine.processEvent(.showRecoveryKeyScreen)
case .presentEncryptionResetScreen:
stateMachine.processEvent(.startEncryptionResetFlow)
case .presentStartChatScreen:
stateMachine.processEvent(.showStartChatScreen)
case .presentGlobalSearch:
Expand Down Expand Up @@ -697,7 +712,59 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
navigationSplitCoordinator.setOverlayCoordinator(nil)
}

// MARK: Secure backup confirmation
// MARK: Secure backup

private func presentRecoveryKeyScreen(animated: Bool) {
let sheetNavigationStackCoordinator = NavigationStackCoordinator()
let parameters = SecureBackupRecoveryKeyScreenCoordinatorParameters(secureBackupController: userSession.clientProxy.secureBackupController,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
isModallyPresented: true)

let coordinator = SecureBackupRecoveryKeyScreenCoordinator(parameters: parameters)
coordinator.actions.sink { [weak self] action in
guard let self else { return }
switch action {
case .complete:
navigationSplitCoordinator.setSheetCoordinator(nil)
}
}
.store(in: &cancellables)

sheetNavigationStackCoordinator.setRootCoordinator(coordinator)

navigationSplitCoordinator.setSheetCoordinator(sheetNavigationStackCoordinator, animated: animated) { [weak self] in
self?.stateMachine.processEvent(.dismissedRecoveryKeyScreen)
}
}

private func startEncryptionResetFlow(animated: Bool) {
let sheetNavigationStackCoordinator = NavigationStackCoordinator()
let parameters = EncryptionResetFlowCoordinatorParameters(userSession: userSession,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
navigationStackCoordinator: sheetNavigationStackCoordinator,
windowManger: appMediator.windowManager)

let coordinator = EncryptionResetFlowCoordinator(parameters: parameters)
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .resetComplete:
encryptionResetFlowCoordinator = nil
navigationSplitCoordinator.setSheetCoordinator(nil)
case .cancel:
encryptionResetFlowCoordinator = nil
navigationSplitCoordinator.setSheetCoordinator(nil)
}
}
.store(in: &cancellables)

coordinator.start()
encryptionResetFlowCoordinator = coordinator

navigationSplitCoordinator.setSheetCoordinator(sheetNavigationStackCoordinator, animated: animated) { [weak self] in
self?.stateMachine.processEvent(.finishedEncryptionResetFlow)
}
}

private func presentSecureBackupLogoutConfirmationScreen() {
let coordinator = SecureBackupLogoutConfirmationScreenCoordinator(parameters: .init(secureBackupController: userSession.clientProxy.secureBackupController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class UserSessionFlowCoordinatorStateMachine {
/// Showing the settings screen
case settingsScreen(selectedRoomID: String?)

/// Showing the recovery key screen.
case recoveryKeyScreen(selectedRoomID: String?)

/// Showing the encryption reset flow.
case encryptionResetFlow(selectedRoomID: String?)

/// Showing the start chat screen
case startChatScreen(selectedRoomID: String?)

Expand All @@ -44,6 +50,8 @@ class UserSessionFlowCoordinatorStateMachine {
case .roomList(let selectedRoomID),
.feedbackScreen(let selectedRoomID),
.settingsScreen(let selectedRoomID),
.recoveryKeyScreen(let selectedRoomID),
.encryptionResetFlow(let selectedRoomID),
.startChatScreen(let selectedRoomID),
.logoutConfirmationScreen(let selectedRoomID),
.roomDirectorySearchScreen(let selectedRoomID):
Expand Down Expand Up @@ -79,12 +87,22 @@ class UserSessionFlowCoordinatorStateMachine {
/// The feedback screen has been dismissed
case dismissedFeedbackScreen

/// Request presentation of the recovery key screen.
case showRecoveryKeyScreen
/// The recovery key screen has been dismissed.
case dismissedRecoveryKeyScreen

/// Request presentation of the encryption reset flow.
case startEncryptionResetFlow
/// The encryption reset flow is complete and has been dismissed.
case finishedEncryptionResetFlow

/// Request the start of the start chat flow
case showStartChatScreen
/// Start chat has been dismissed
case dismissedStartChatScreen

/// Logout has been requested and this is the last sesion
/// Logout has been requested and this is the last session
case showLogoutConfirmationScreen
/// Logout has been cancelled
case dismissedLogoutConfirmationScreen
Expand Down Expand Up @@ -136,6 +154,16 @@ class UserSessionFlowCoordinatorStateMachine {
case (.feedbackScreen(let selectedRoomID), .dismissedFeedbackScreen):
return .roomList(selectedRoomID: selectedRoomID)

case (.roomList(let selectedRoomID), .showRecoveryKeyScreen):
return .recoveryKeyScreen(selectedRoomID: selectedRoomID)
case (.recoveryKeyScreen(let selectedRoomID), .dismissedRecoveryKeyScreen):
return .roomList(selectedRoomID: selectedRoomID)

case (.roomList(let selectedRoomID), .startEncryptionResetFlow):
return .encryptionResetFlow(selectedRoomID: selectedRoomID)
case (.encryptionResetFlow(let selectedRoomID), .finishedEncryptionResetFlow):
return .roomList(selectedRoomID: selectedRoomID)

case (.roomList(let selectedRoomID), .showStartChatScreen):
return .startChatScreen(selectedRoomID: selectedRoomID)
case (.startChatScreen(let selectedRoomID), .dismissedStartChatScreen):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ enum HomeScreenCoordinatorAction {
case roomLeft(roomIdentifier: String)
case presentSettingsScreen
case presentFeedbackScreen
case presentSecureBackupSettings
case presentRecoveryKeyScreen
case presentEncryptionResetScreen
case presentStartChatScreen
case presentGlobalSearch
case presentRoomDirectorySearch
Expand Down Expand Up @@ -63,8 +64,10 @@ final class HomeScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.presentFeedbackScreen)
case .presentSettingsScreen:
actionsSubject.send(.presentSettingsScreen)
case .presentSecureBackupSettings:
actionsSubject.send(.presentSecureBackupSettings)
case .presentRecoveryKeyScreen:
actionsSubject.send(.presentRecoveryKeyScreen)
case .presentEncryptionResetScreen:
actionsSubject.send(.presentEncryptionResetScreen)
case .presentStartChatScreen:
actionsSubject.send(.presentStartChatScreen)
case .presentGlobalSearch:
Expand Down
6 changes: 4 additions & 2 deletions ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ enum HomeScreenViewModelAction {
case presentRoom(roomIdentifier: String)
case presentRoomDetails(roomIdentifier: String)
case roomLeft(roomIdentifier: String)
case presentSecureBackupSettings
case presentRecoveryKeyScreen
case presentEncryptionResetScreen
case presentSettingsScreen
case presentFeedbackScreen
case presentStartChatScreen
Expand All @@ -30,7 +31,8 @@ enum HomeScreenViewAction {
case confirmLeaveRoom(roomIdentifier: String)
case showSettings
case startChat
case confirmRecoveryKey
case manageRecoveryKey
case resetEncryption
case skipRecoveryKeyConfirmation
case confirmSlidingSyncUpgrade
case skipSlidingSyncUpgrade
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
Task { await leaveRoom(roomID: roomIdentifier) }
case .showSettings:
actionsSubject.send(.presentSettingsScreen)
case .confirmRecoveryKey:
actionsSubject.send(.presentSecureBackupSettings)
case .manageRecoveryKey:
actionsSubject.send(.presentRecoveryKeyScreen)
case .resetEncryption:
actionsSubject.send(.presentEncryptionResetScreen)
case .skipRecoveryKeyConfirmation:
state.securityBannerMode = .dismissed
case .confirmSlidingSyncUpgrade:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ struct HomeScreenRecoveryKeyConfirmationBanner: View {
var buttons: some View {
VStack(spacing: 16) {
Button(actionTitle) {
context.send(viewAction: .confirmRecoveryKey)
context.send(viewAction: .manageRecoveryKey)
}
.frame(maxWidth: .infinity)
.buttonStyle(.compound(.primary, size: .medium))
.accessibilityIdentifier(A11yIdentifiers.homeScreen.recoveryKeyConfirmationBannerContinue)

if !requiresExtraAccountSetup {
// Missing encryption reset button to goes here once the flow exists.
Button {
context.send(viewAction: .resetEncryption)
} label: {
Text(L10n.confirmRecoveryKeyBannerSecondaryButtonTitle)
.padding(.vertical, 7)
.frame(maxWidth: .infinity)
}
.buttonStyle(.compound(.plain, size: .medium))
}
}
}
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.
Loading