|
@@ -25,7 +25,6 @@ class NewChatViewController: UITableViewController {
|
|
return searchController
|
|
return searchController
|
|
}()
|
|
}()
|
|
|
|
|
|
-
|
|
|
|
var contactIds: [Int] = Utils.getContactIds() {
|
|
var contactIds: [Int] = Utils.getContactIds() {
|
|
didSet {
|
|
didSet {
|
|
tableView.reloadData()
|
|
tableView.reloadData()
|
|
@@ -40,7 +39,6 @@ class NewChatViewController: UITableViewController {
|
|
// used when seachbar is active
|
|
// used when seachbar is active
|
|
var filteredContacts: [ContactWithSearchResults] = []
|
|
var filteredContacts: [ContactWithSearchResults] = []
|
|
|
|
|
|
-
|
|
|
|
// searchBar active?
|
|
// searchBar active?
|
|
func isFiltering() -> Bool {
|
|
func isFiltering() -> Bool {
|
|
return searchController.isActive && !searchBarIsEmpty()
|
|
return searchController.isActive && !searchBarIsEmpty()
|
|
@@ -141,8 +139,6 @@ class NewChatViewController: UITableViewController {
|
|
return deviceContactAccessGranted ? 2 : 3
|
|
return deviceContactAccessGranted ? 2 : 3
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
if section == 0 {
|
|
if section == 0 {
|
|
return 3
|
|
return 3
|
|
@@ -157,8 +153,6 @@ class NewChatViewController: UITableViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let section = indexPath.section
|
|
let section = indexPath.section
|
|
let row = indexPath.row
|
|
let row = indexPath.row
|
|
@@ -242,7 +236,6 @@ class NewChatViewController: UITableViewController {
|
|
return UITableViewCell(style: .default, reuseIdentifier: "cell")
|
|
return UITableViewCell(style: .default, reuseIdentifier: "cell")
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
override func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
override func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
let row = indexPath.row
|
|
let row = indexPath.row
|
|
let section = indexPath.section
|
|
let section = indexPath.section
|
|
@@ -271,11 +264,21 @@ class NewChatViewController: UITableViewController {
|
|
navigationController?.pushViewController(newContactController, animated: true)
|
|
navigationController?.pushViewController(newContactController, animated: true)
|
|
}
|
|
}
|
|
} else if section == 1 {
|
|
} else if section == 1 {
|
|
|
|
+
|
|
if deviceContactAccessGranted {
|
|
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 {
|
|
} else {
|
|
showSettingsAlert()
|
|
showSettingsAlert()
|