Handle no results

In line with other messaging apps, we intentionally don't show a "No Results"
cell. We simply don't display any cells. Though we could easily modify this in
the future.

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 91af7d3855
commit ecdaad06ff

@ -19,9 +19,10 @@ class ConversationSearchViewController: UITableViewController {
} }
enum SearchSection: Int { enum SearchSection: Int {
case conversations = 0 case noResults
case contacts = 1 case conversations
case messages = 2 case contacts
case messages
} }
// MARK: View Lifecyle // MARK: View Lifecyle
@ -41,39 +42,41 @@ class ConversationSearchViewController: UITableViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false) tableView.deselectRow(at: indexPath, animated: false)
guard let searchSection = SearchSection(rawValue: indexPath.section) else { guard let searchSection = SearchSection(rawValue: indexPath.section) else {
owsFail("\(logTag) unknown section selected.") owsFail("\(logTag) unknown section selected.")
return return
} }
switch searchSection { switch searchSection {
case .noResults:
owsFail("\(logTag) shouldn't be able to tap 'no results' section")
case .conversations: case .conversations:
let sectionResults = searchResultSet.conversations let sectionResults = searchResultSet.conversations
guard let searchResult = sectionResults[safe: indexPath.row] else { guard let searchResult = sectionResults[safe: indexPath.row] else {
owsFail("\(logTag) unknown row selected.") owsFail("\(logTag) unknown row selected.")
return return
} }
let thread = searchResult.thread let thread = searchResult.thread
SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose) SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose)
case .contacts: case .contacts:
let sectionResults = searchResultSet.contacts let sectionResults = searchResultSet.contacts
guard let searchResult = sectionResults[safe: indexPath.row] else { guard let searchResult = sectionResults[safe: indexPath.row] else {
owsFail("\(logTag) unknown row selected.") owsFail("\(logTag) unknown row selected.")
return return
} }
SignalApp.shared().presentConversation(forRecipientId: searchResult.recipientId, action: .compose) SignalApp.shared().presentConversation(forRecipientId: searchResult.recipientId, action: .compose)
case .messages: case .messages:
let sectionResults = searchResultSet.messages let sectionResults = searchResultSet.messages
guard let searchResult = sectionResults[safe: indexPath.row] else { guard let searchResult = sectionResults[safe: indexPath.row] else {
owsFail("\(logTag) unknown row selected.") owsFail("\(logTag) unknown row selected.")
return return
} }
let thread = searchResult.thread let thread = searchResult.thread
SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose) SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose)
} }
@ -88,6 +91,9 @@ class ConversationSearchViewController: UITableViewController {
} }
switch searchSection { switch searchSection {
case .noResults:
// We don't display a "no results" cell, we simply display no results.
return 0
case .conversations: case .conversations:
return searchResultSet.conversations.count return searchResultSet.conversations.count
case .contacts: case .contacts:
@ -104,6 +110,8 @@ class ConversationSearchViewController: UITableViewController {
} }
switch searchSection { switch searchSection {
case .noResults:
return UITableViewCell()
case .conversations: case .conversations:
guard let cell = tableView.dequeueReusableCell(withIdentifier: ConversationSearchResultCell.reuseIdentifier) as? ConversationSearchResultCell else { guard let cell = tableView.dequeueReusableCell(withIdentifier: ConversationSearchResultCell.reuseIdentifier) as? ConversationSearchResultCell else {
return UITableViewCell() return UITableViewCell()
@ -150,6 +158,8 @@ class ConversationSearchViewController: UITableViewController {
} }
switch searchSection { switch searchSection {
case .noResults:
return nil
case .conversations: case .conversations:
if searchResultSet.conversations.count > 0 { if searchResultSet.conversations.count > 0 {
return NSLocalizedString("SEARCH_SECTION_CONVERSATIONS", comment: "section header for search results that match existing conversations (either group or contact conversations)") return NSLocalizedString("SEARCH_SECTION_CONVERSATIONS", comment: "section header for search results that match existing conversations (either group or contact conversations)")

@ -986,9 +986,6 @@
/* A label for conversations with blocked users. */ /* A label for conversations with blocked users. */
"HOME_VIEW_BLOCKED_CONTACT_CONVERSATION" = "Blocked"; "HOME_VIEW_BLOCKED_CONTACT_CONVERSATION" = "Blocked";
/* Placeholder text for search bar which filters conversations. */
"HOME_VIEW_CONVERSATION_SEARCHBAR_PLACEHOLDER" = "Search";
/* Title for the home view's 'archive' mode. */ /* Title for the home view's 'archive' mode. */
"HOME_VIEW_TITLE_ARCHIVE" = "Archive"; "HOME_VIEW_TITLE_ARCHIVE" = "Archive";

@ -40,6 +40,10 @@ public class SearchResultSet {
public class var empty: SearchResultSet { public class var empty: SearchResultSet {
return SearchResultSet(conversations: [], contacts: [], messages: []) return SearchResultSet(conversations: [], contacts: [], messages: [])
} }
public var isEmpty: Bool {
return conversations.isEmpty && contacts.isEmpty && messages.isEmpty
}
} }
@objc @objc

Loading…
Cancel
Save