Jelajahi Sumber

Merge pull request #372 from deltachat/empty-server

add options to empty the server
björn petersen 5 tahun lalu
induk
melakukan
e5e3599150

+ 34 - 1
deltachat-ios/Controller/AccountSetupController.swift

@@ -105,6 +105,14 @@ class AccountSetupController: UITableViewController {
         return cell
     }()
 
+    private lazy var emptyServerCell: ActionCell = {
+        let cell = ActionCell(frame: .zero)
+        cell.actionTitle = String.localized("pref_empty_server_title")
+        cell.actionColor = UIColor.red
+        cell.accessibilityIdentifier = "emptyServerCell"
+        return cell
+    }()
+
     private lazy var deleteAccountCell: ActionCell = {
         let cell = ActionCell(frame: .zero)
         cell.actionTitle = String.localized("delete_account")
@@ -238,7 +246,7 @@ class AccountSetupController: UITableViewController {
         smtpPasswordCell,
         smtpSecurityCell
     ]
-    private lazy var dangerCells: [UITableViewCell] = [deleteAccountCell]
+    private lazy var dangerCells: [UITableViewCell] = [emptyServerCell, deleteAccountCell]
 
     private let editView: Bool
     private var advancedSectionShowing: Bool = false
@@ -372,6 +380,8 @@ class AccountSetupController: UITableViewController {
         if tappedCell.accessibilityIdentifier == "restoreCell" {
             tableView.reloadData() // otherwise the disclosureIndicator may stay selected
             restoreBackup()
+        } else if tappedCell.accessibilityIdentifier == "emptyServerCell" {
+            emptyServer()
         } else if tappedCell.accessibilityIdentifier == "deleteAccountCell" {
             deleteAccount()
         } else if tappedCell.accessibilityIdentifier == "advancedShowCell" {
@@ -597,6 +607,29 @@ class AccountSetupController: UITableViewController {
         logger.error("no documents directory found")
     }
 
+    private func emptyServer() {
+        let alert = UIAlertController(title: String.localized("pref_empty_server_title"),
+            message: String.localized("pref_empty_server_msg"), preferredStyle: .actionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("pref_empty_server_inbox"), style: .destructive, handler: { _ in
+            self.emptyServer2ndConfirm(title: String.localized("pref_empty_server_inbox"), flags: Int(DC_EMPTY_INBOX))
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("pref_empty_server_mvbox"), style: .destructive, handler: { _ in
+            self.emptyServer2ndConfirm(title: String.localized("pref_empty_server_mvbox"), flags: Int(DC_EMPTY_MVBOX))
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
+        present(alert, animated: true, completion: nil)
+    }
+
+    private func emptyServer2ndConfirm(title: String, flags: Int) {
+        let alert = UIAlertController(title: title,
+            message: String.localized("pref_empty_server_msg"), preferredStyle: .alert)
+        alert.addAction(UIAlertAction(title: String.localized("pref_empty_server_do_button"), style: .destructive, handler: { _ in
+            self.dcContext.emptyServer(flags: flags)
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
+        present(alert, animated: true, completion: nil)
+    }
+
     private func deleteAccount() {
         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
             return

+ 4 - 0
deltachat-ios/DC/Wrapper.swift

@@ -125,6 +125,10 @@ class DcContext {
     func getUnreadMessages(chatId: Int) -> Int {
         return Int(dc_get_fresh_msg_cnt(contextPointer, UInt32(chatId)))
     }
+
+    func emptyServer(flags: Int) {
+        dc_empty_server(contextPointer, UInt32(flags))
+    }
 }
 
 class DcConfig {