mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Adopt StateStoreViewModelV2 in the remaining settings screens. (#4158)
* Move the AuthenticationStartScreen into the Authentication directory.
* Commit the updated Sentry license.
No idea why they dropped the 2024 🤷♂️
* Use StateStoreViewModelV2 in BugReportScreen.
* Use StateStoreViewModelV2 in UserDetailsEditScreen.
* Use StateStoreViewModelV2 in NotificationSettingsScreen.
* Use StateStoreViewModelV2 in NotificationSettingsEditScreen.
* Use StateStoreViewModelV2 in LegalInformationScreen.
* Use StateStoreViewModelV2 in LogViewerScreen.
* Use StateStoreViewModelV2 in AnalyticsSettingsScreen.
* Rename AdvancedSettingsScreen directory.
* Use StateStoreViewModelV2 in EncryptionResetScreen.
* Use StateStoreViewModelV2 in EncryptionResetPasswordScreen.
* Use StateStoreViewModelV2 in SecureBackup…Screens.
* Use StateStoreViewModelV2 in LoginScreen.
Seems this one was ignored waiting on the fulfillment transitionValues implementation.
* Use StateStoreViewModelV2 in DeactivateAccountScreen.
* Move DeactivateAccountScreen into the Settings directory.
This commit is contained in:
+82
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias DeactivateAccountScreenViewModelType = StateStoreViewModelV2<DeactivateAccountScreenViewState, DeactivateAccountScreenViewAction>
|
||||
|
||||
class DeactivateAccountScreenViewModel: DeactivateAccountScreenViewModelType, DeactivateAccountScreenViewModelProtocol {
|
||||
private let clientProxy: ClientProxyProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<DeactivateAccountScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<DeactivateAccountScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(clientProxy: ClientProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: DeactivateAccountScreenViewState())
|
||||
}
|
||||
|
||||
override func process(viewAction: DeactivateAccountScreenViewAction) {
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .deactivate:
|
||||
showDeactivationConfirmation()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private let deactivatingIndicatorID = "\(DeactivateAccountScreenViewModel.self)-Deactivating"
|
||||
|
||||
func showDeactivationConfirmation() {
|
||||
state.bindings.alertInfo = .init(id: .confirmation,
|
||||
title: L10n.screenDeactivateAccountTitle,
|
||||
message: L10n.screenDeactivateAccountConfirmationDialogContent,
|
||||
primaryButton: .init(title: L10n.actionDeactivate) {
|
||||
Task { await self.deactivateAccount() }
|
||||
},
|
||||
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil))
|
||||
}
|
||||
|
||||
func deactivateAccount() async {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: deactivatingIndicatorID,
|
||||
type: .modal(progress: .indeterminate, interactiveDismissDisabled: true, allowsInteraction: false),
|
||||
title: L10n.commonPleaseWait,
|
||||
persistent: true))
|
||||
|
||||
MXLog.warning("Deactivating account.")
|
||||
|
||||
switch await clientProxy.deactivateAccount(password: nil, eraseData: state.bindings.eraseData) {
|
||||
case .success:
|
||||
MXLog.info("Account deactivated (no password needed).")
|
||||
actionsSubject.send(.accountDeactivated)
|
||||
return
|
||||
case .failure:
|
||||
MXLog.info("Request failed, including password.")
|
||||
}
|
||||
|
||||
switch await clientProxy.deactivateAccount(password: state.bindings.password, eraseData: state.bindings.eraseData) {
|
||||
case .success:
|
||||
MXLog.info("Account deactivated.")
|
||||
actionsSubject.send(.accountDeactivated)
|
||||
return
|
||||
case .failure(let failure):
|
||||
MXLog.info("Deactivation failed \(failure).")
|
||||
state.bindings.alertInfo = .init(id: .deactivationFailed,
|
||||
title: L10n.errorUnknown,
|
||||
message: String(describing: failure))
|
||||
userIndicatorController.retractIndicatorWithId(deactivatingIndicatorID)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user