Эх сурвалжийг харах

bugfix - device import would not have updated contacts table per se

Bastian van de Wetering 6 жил өмнө
parent
commit
1d186d5ce0

+ 7 - 5
deltachat-ios/DeviceContactsHandler.swift

@@ -11,6 +11,7 @@ import UIKit
 
 
 class DeviceContactsHandler {
 class DeviceContactsHandler {
   private let store = CNContactStore()
   private let store = CNContactStore()
+	weak var contactListDelegate: ContactListDelegate?
 
 
   private func makeContactString(contacts: [CNContact]) -> String {
   private func makeContactString(contacts: [CNContact]) -> String {
     var contactString: String = ""
     var contactString: String = ""
@@ -28,6 +29,7 @@ class DeviceContactsHandler {
     let storedContacts = fetchContactsWithEmailFromDevice()
     let storedContacts = fetchContactsWithEmailFromDevice()
     let contactString = makeContactString(contacts: storedContacts)
     let contactString = makeContactString(contacts: storedContacts)
     dc_add_address_book(mailboxPointer, contactString)
     dc_add_address_book(mailboxPointer, contactString)
+		contactListDelegate?.deviceContactsImported()
   }
   }
 
 
   private func fetchContactsWithEmailFromDevice() -> [CNContact] {
   private func fetchContactsWithEmailFromDevice() -> [CNContact] {
@@ -55,23 +57,23 @@ class DeviceContactsHandler {
     return fetchedContacts
     return fetchedContacts
   }
   }
 
 
-  public func importDeviceContacts(delegate: DeviceContactsDelegate?) {
+  public func importDeviceContacts() {
     switch CNContactStore.authorizationStatus(for: .contacts) {
     switch CNContactStore.authorizationStatus(for: .contacts) {
     case .authorized:
     case .authorized:
       addContactsToCore()
       addContactsToCore()
-      delegate?.accessGranted()
+      self.contactListDelegate?.accessGranted()
     case .denied:
     case .denied:
-      delegate?.accessDenied()
+      self.contactListDelegate?.accessDenied()
     case .restricted, .notDetermined:
     case .restricted, .notDetermined:
       store.requestAccess(for: .contacts) { [unowned self] granted, _ in
       store.requestAccess(for: .contacts) { [unowned self] granted, _ in
         if granted {
         if granted {
           DispatchQueue.main.async {
           DispatchQueue.main.async {
             self.addContactsToCore()
             self.addContactsToCore()
-            delegate?.accessGranted()
+            self.contactListDelegate?.accessGranted()
           }
           }
         } else {
         } else {
           DispatchQueue.main.async {
           DispatchQueue.main.async {
-            delegate?.accessDenied()
+            self.contactListDelegate?.accessDenied()
           }
           }
         }
         }
       }
       }

+ 14 - 4
deltachat-ios/NewChatViewController.swift

@@ -49,7 +49,11 @@ class NewChatViewController: UITableViewController {
   var syncObserver: Any?
   var syncObserver: Any?
   var hud: ProgressHud?
   var hud: ProgressHud?
 
 
-  let deviceContactHandler = DeviceContactsHandler()
+	lazy var deviceContactHandler: DeviceContactsHandler = {
+		let handler = DeviceContactsHandler()
+		handler.contactListDelegate = self
+		return handler
+	}()
   var deviceContactAccessGranted: Bool = false {
   var deviceContactAccessGranted: Bool = false {
     didSet {
     didSet {
       tableView.reloadData()
       tableView.reloadData()
@@ -73,7 +77,7 @@ class NewChatViewController: UITableViewController {
     let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(NewChatViewController.cancelButtonPressed))
     let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(NewChatViewController.cancelButtonPressed))
     navigationItem.rightBarButtonItem = cancelButton
     navigationItem.rightBarButtonItem = cancelButton
 
 
-    deviceContactHandler.importDeviceContacts(delegate: self)
+    deviceContactHandler.importDeviceContacts()
 		navigationItem.searchController = searchController
 		navigationItem.searchController = searchController
 		definesPresentationContext = true // to make sure searchbar will only be shown in this viewController
 		definesPresentationContext = true // to make sure searchbar will only be shown in this viewController
   }
   }
@@ -371,7 +375,12 @@ extension NewChatViewController: QrCodeReaderDelegate {
   }
   }
 }
 }
 
 
-extension NewChatViewController: DeviceContactsDelegate {
+extension NewChatViewController: ContactListDelegate {
+	func deviceContactsImported() {
+		self.contactIds = Utils.getContactIds()
+//		tableView.reloadData()
+	}
+
   func accessGranted() {
   func accessGranted() {
     deviceContactAccessGranted = true
     deviceContactAccessGranted = true
   }
   }
@@ -403,9 +412,10 @@ extension NewChatViewController: UISearchResultsUpdating {
 	}
 	}
 }
 }
 
 
-protocol DeviceContactsDelegate {
+protocol ContactListDelegate: class {
   func accessGranted()
   func accessGranted()
   func accessDenied()
   func accessDenied()
+	func deviceContactsImported()
 }
 }
 
 
 // TODO: find better name
 // TODO: find better name