mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
More secure backup tweaks (#2212)
* Make sure the indicator for disabling backups is dismissed together with the screen * Get rid of the .disabled key backup state as it has no correspondant on the rust side and is confusing * Remove superflous BackupState extensions, add more logs
This commit is contained in:
+17
-4
@@ -21,6 +21,7 @@ typealias SecureBackupKeyBackupScreenViewModelType = StateStoreViewModel<SecureB
|
||||
|
||||
class SecureBackupKeyBackupScreenViewModel: SecureBackupKeyBackupScreenViewModelType, SecureBackupKeyBackupScreenViewModelProtocol {
|
||||
private let secureBackupController: SecureBackupControllerProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol?
|
||||
|
||||
private var actionsSubject: PassthroughSubject<SecureBackupKeyBackupScreenViewModelAction, Never> = .init()
|
||||
var actions: AnyPublisher<SecureBackupKeyBackupScreenViewModelAction, Never> {
|
||||
@@ -29,18 +30,18 @@ class SecureBackupKeyBackupScreenViewModel: SecureBackupKeyBackupScreenViewModel
|
||||
|
||||
init(secureBackupController: SecureBackupControllerProtocol, userIndicatorController: UserIndicatorControllerProtocol?) {
|
||||
self.secureBackupController = secureBackupController
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: .init(mode: secureBackupController.keyBackupState.value.viewMode))
|
||||
|
||||
secureBackupController.keyBackupState
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak userIndicatorController] state in
|
||||
let loadingIndicatorIdentifier = "SecureBackupKeyBackupScreenLoading"
|
||||
.sink { [weak self] state in
|
||||
switch state {
|
||||
case .disabling, .enabling, .unknown:
|
||||
userIndicatorController?.submitIndicator(.init(id: loadingIndicatorIdentifier, type: .modal, title: L10n.commonLoading, persistent: true))
|
||||
self?.showLoadingIndicator()
|
||||
default:
|
||||
userIndicatorController?.retractIndicatorWithId(loadingIndicatorIdentifier)
|
||||
self?.dismissLoadingIndicator()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@@ -80,8 +81,20 @@ class SecureBackupKeyBackupScreenViewModel: SecureBackupKeyBackupScreenViewModel
|
||||
MXLog.error("Failed disabling key backup with error: \(error)")
|
||||
state.bindings.alertInfo = .init(id: .init())
|
||||
}
|
||||
|
||||
dismissLoadingIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "SecureBackupKeyBackupScreenLoading"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController?.submitIndicator(.init(id: Self.loadingIndicatorIdentifier, type: .modal, title: L10n.commonLoading, persistent: true))
|
||||
}
|
||||
|
||||
private func dismissLoadingIndicator() {
|
||||
userIndicatorController?.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
extension SecureBackupKeyBackupState {
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ class SecureBackupScreenViewModel: SecureBackupScreenViewModelType, SecureBackup
|
||||
actionsSubject.send(.recoveryKey)
|
||||
case .keyBackup:
|
||||
switch secureBackupController.keyBackupState.value {
|
||||
case .disabled, .unknown:
|
||||
case .unknown:
|
||||
enableBackup()
|
||||
case .enabled:
|
||||
actionsSubject.send(.keyBackup)
|
||||
|
||||
+3
-5
@@ -23,7 +23,7 @@ struct SecureBackupScreen: View {
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
if context.viewState.keyBackupState == .disabled {
|
||||
if context.viewState.keyBackupState == .unknown {
|
||||
keyBackupSection
|
||||
} else {
|
||||
keyBackupSection
|
||||
@@ -77,12 +77,10 @@ struct SecureBackupScreen: View {
|
||||
ListRow(label: .plain(title: L10n.screenChatBackupKeyBackupActionDisable, role: .destructive), kind: .navigationLink {
|
||||
context.send(viewAction: .keyBackup)
|
||||
})
|
||||
case .disabled, .enabling:
|
||||
case .unknown, .enabling:
|
||||
ListRow(label: .plain(title: L10n.screenChatBackupKeyBackupActionEnable), kind: .navigationLink {
|
||||
context.send(viewAction: .keyBackup)
|
||||
})
|
||||
case .unknown:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +126,7 @@ struct SecureBackupScreen: View {
|
||||
struct SecureBackupScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let bothSetupViewModel = viewModel(keyBackupState: .enabled, recoveryKeyState: .enabled)
|
||||
static let onlyKeyBackupSetUpViewModel = viewModel(keyBackupState: .enabled, recoveryKeyState: .disabled)
|
||||
static let keyBackupDisabledViewModel = viewModel(keyBackupState: .disabled, recoveryKeyState: .disabled)
|
||||
static let keyBackupDisabledViewModel = viewModel(keyBackupState: .unknown, recoveryKeyState: .disabled)
|
||||
static let recoveryIncompleteViewModel = viewModel(keyBackupState: .enabled, recoveryKeyState: .incomplete)
|
||||
|
||||
static var previews: some View {
|
||||
|
||||
Reference in New Issue
Block a user