浏览代码

handle didSelect event when searchController is active

Bastian van de Wetering 6 年之前
父节点
当前提交
e3563386a9
共有 1 个文件被更改,包括 14 次插入11 次删除
  1. 14 11
      deltachat-ios/NewChatViewController.swift

+ 14 - 11
deltachat-ios/NewChatViewController.swift

@@ -25,7 +25,6 @@ class NewChatViewController: UITableViewController {
 		return searchController
 	}()
 
-
 	var contactIds: [Int] = Utils.getContactIds() {
 		didSet {
 			tableView.reloadData()
@@ -40,7 +39,6 @@ class NewChatViewController: UITableViewController {
 	// used when seachbar is active
 	var filteredContacts: [ContactWithSearchResults] = []
 
-
 	// searchBar active?
 	func isFiltering() -> Bool {
 		return searchController.isActive && !searchBarIsEmpty()
@@ -141,8 +139,6 @@ class NewChatViewController: UITableViewController {
 		return deviceContactAccessGranted ? 2 : 3
   }
 
-
-
   override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
 		if section == 0 {
 			return 3
@@ -157,8 +153,6 @@ class NewChatViewController: UITableViewController {
 		}
   }
 
-
-
   override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 		let section = indexPath.section
     let row = indexPath.row
@@ -242,7 +236,6 @@ class NewChatViewController: UITableViewController {
 		return UITableViewCell(style: .default, reuseIdentifier: "cell")
   }
 
-
   override func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
     let row = indexPath.row
 		let section = indexPath.section
@@ -271,11 +264,21 @@ class NewChatViewController: UITableViewController {
 				navigationController?.pushViewController(newContactController, animated: true)
 			}
 		} else if section == 1 {
+
 			if deviceContactAccessGranted {
-				let contactIndex = row
-				let contactId = contactIds[contactIndex]
-				dismiss(animated: false) {
-					self.chatDisplayer?.displayNewChat(contactId: contactId)
+				if searchController.isActive {
+					// edge case: when searchController is active but searchBar is empty -> filteredContacts is empty, so we fallback to contactIds
+					let contactId = isFiltering() ? filteredContacts[row].contact.id : self.contactIds[row]
+					searchController.dismiss(animated: false, completion: {
+						self.dismiss(animated: false, completion: {
+							self.chatDisplayer?.displayNewChat(contactId: contactId)
+						})
+					})
+				} else {
+					let contactId = contactIds[row]
+					dismiss(animated: false) {
+						self.chatDisplayer?.displayNewChat(contactId: contactId)
+					}
 				}
 			} else {
 				showSettingsAlert()