Browse Source

unblock blocked contacts in app settings (#211)

cyberta 5 năm trước cách đây
mục cha
commit
f9109794a8

+ 42 - 0
deltachat-ios/Controller/GroupMembersViewController.swift

@@ -97,8 +97,48 @@ class AddGroupMembersViewController: GroupMembersViewController {
     }
 }
 
+class BlockedContactsViewController: GroupMembersViewController, GroupMemberSelectionDelegate {
+
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        title = String.localized("pref_blocked_contacts")
+        contactIds = Utils.getBlockedContactIds()
+        selectedContactIds = Set(contactIds)
+        navigationItem.searchController = nil
+        groupMemberSelectionDelegate = self
+    }
+
+    override func viewWillAppear(_ animated: Bool) {
+        super.viewWillAppear(animated)
+        NavBarUtils.setSmallTitle(navigationController: navigationController)
+    }
+
+    func selected(contactId: Int, selected: Bool) {
+        if !selected {
+            let alert = UIAlertController(title: nil, message: String.localized("ask_unblock_contact"), preferredStyle: .actionSheet)
+            alert.addAction(UIAlertAction(title: String.localized("menu_unblock_contact"), style: .default, handler: { _ in
+                let contact = DcContact(id: contactId)
+                contact.unblock()
+                self.contactIds = Utils.getBlockedContactIds()
+                self.selectedContactIds = Set(self.contactIds)
+                self.tableView.reloadData()
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
+                self.selectedContactIds = Set(self.contactIds)
+                self.tableView.reloadData()
+            }))
+           present(alert, animated: true, completion: nil)
+        }
+    }
+}
+
+protocol GroupMemberSelectionDelegate: class {
+    func selected(contactId: Int, selected: Bool)
+}
+
 class GroupMembersViewController: UITableViewController, UISearchResultsUpdating {
     let contactCellReuseIdentifier = "contactCell"
+    weak var groupMemberSelectionDelegate: GroupMemberSelectionDelegate?
 
     var contactIds: [Int] = [] {
         didSet {
@@ -187,9 +227,11 @@ class GroupMembersViewController: UITableViewController, UISearchResultsUpdating
             if selectedContactIds.contains(contactId) {
                 selectedContactIds.remove(contactId)
                 cell.accessoryType = .none
+                groupMemberSelectionDelegate?.selected(contactId: contactId, selected: false)
             } else {
                 selectedContactIds.insert(contactId)
                 cell.accessoryType = .checkmark
+                groupMemberSelectionDelegate?.selected(contactId: contactId, selected: true)
             }
         }
     }

+ 5 - 0
deltachat-ios/Controller/SettingsController.swift

@@ -109,6 +109,7 @@ internal final class SettingsViewController: QuickTableViewController {
             Section(
                 title: String.localized("pref_communication"),
                 rows: [
+                    TapActionRow(text: String.localized("pref_blocked_contacts"), action: { [weak self] in self?.showBlockedContacts($0) }),
                     SwitchRow(text: String.localized("pref_read_receipts"),
                               switchValue: DcConfig.mdnsEnabled,
                               action: { row in
@@ -206,6 +207,10 @@ internal final class SettingsViewController: QuickTableViewController {
         present(alert, animated: true, completion: nil)
     }
 
+    private func showBlockedContacts(_: Row) {
+        coordinator?.showBlockedContacts()
+    }
+
     private func sendAsm(_: Row) {
         let askAlert = UIAlertController(title: String.localized("autocrypt_send_asm_explain_before"), message: nil, preferredStyle: .actionSheet)
         askAlert.addAction(UIAlertAction(title: String.localized("autocrypt_send_asm_title"), style: .default, handler: { _ in

+ 5 - 0
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -206,6 +206,11 @@ class SettingsCoordinator: Coordinator {
         let accountSetupNavigationController = DcNavigationController(rootViewController: accountSetupVC)
         navigationController.present(accountSetupNavigationController, animated: true, completion: nil)
     }
+
+    func showBlockedContacts() {
+        let blockedContactsController = BlockedContactsViewController()
+        navigationController.pushViewController(blockedContactsController, animated: true)
+    }
 }
 
 class AccountSetupCoordinator: Coordinator {