From 0307eba6ef9aca71a4c46819447070cb36998549 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 12 Jul 2021 14:07:42 +1000 Subject: [PATCH] Debug --- .../Translations/en.lproj/Localizable.strings | 2 ++ Session/Settings/NukeDataModal.swift | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 5e7354cb3..2accd0394 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -495,6 +495,8 @@ "modal_clear_all_data_title" = "Clear All Data"; "modal_clear_all_data_explanation" = "This will permanently delete your messages, sessions, and contacts."; "modal_clear_all_data_explanation_2" = "Would you like to clear only this device, or delete your entire account?"; +"dialog_clear_all_data_deletion_failed_1" = "Data not deleted by 1 Service Node. Service Node ID: %@."; +"dialog_clear_all_data_deletion_failed_2" = "Data not deleted by %@ Service Nodes. Service Node IDs: %@."; "modal_clear_all_data_device_only_button_title" = "Device Only"; "modal_clear_all_data_entire_account_button_title" = "Entire Account"; "vc_qr_code_title" = "QR Code"; diff --git a/Session/Settings/NukeDataModal.swift b/Session/Settings/NukeDataModal.swift index 2b5be8c01..0246c7ae8 100644 --- a/Session/Settings/NukeDataModal.swift +++ b/Session/Settings/NukeDataModal.swift @@ -132,11 +132,29 @@ final class NukeDataModal : Modal { @objc private func clearEntireAccount() { ModalActivityIndicatorViewController.present(fromViewController: self, canCancel: false) { [weak self] _ in - SnodeAPI.clearAllData().ensure(on: DispatchQueue.main) { + SnodeAPI.clearAllData().done(on: DispatchQueue.main) { confirmations in self?.dismiss(animated: true, completion: nil) // Dismiss the loader - UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later - NotificationCenter.default.post(name: .dataNukeRequested, object: nil) - }.retainUntilComplete() + let potentiallyMaliciousSnodes = confirmations.compactMap { $0.value == false ? $0.key : nil } + if potentiallyMaliciousSnodes.isEmpty { + UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later + NotificationCenter.default.post(name: .dataNukeRequested, object: nil) + } else { + let message: String + if potentiallyMaliciousSnodes.count == 1 { + message = String(format: NSLocalizedString("dialog_clear_all_data_deletion_failed_1", comment: ""), potentiallyMaliciousSnodes[0]) + } else { + message = String(format: NSLocalizedString("dialog_clear_all_data_deletion_failed_2", comment: ""), String(potentiallyMaliciousSnodes.count), potentiallyMaliciousSnodes.joined(separator: ", ")) + } + let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil)) + self?.presentAlert(alert) + } + }.catch(on: DispatchQueue.main) { error in + self?.dismiss(animated: true, completion: nil) // Dismiss the loader + let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil)) + self?.presentAlert(alert) + } } } }