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:
Stefan Ceriu
2023-12-07 13:19:58 +02:00
committed by GitHub
parent e8b446c909
commit 495ee8ab38
5 changed files with 64 additions and 34 deletions
@@ -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 {