diff --git a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift index 90599fcb7..bea9df6b4 100644 --- a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift +++ b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift @@ -41,30 +41,42 @@ class ConversationSearchViewController: UITableViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: false) - + guard let searchSection = SearchSection(rawValue: indexPath.section) else { owsFail("\(logTag) unknown section selected.") return } - - var sectionResults: [SearchResult] + switch searchSection { case .conversations: - sectionResults = searchResultSet.conversations + let sectionResults = searchResultSet.conversations + guard let searchResult = sectionResults[safe: indexPath.row] else { + owsFail("\(logTag) unknown row selected.") + return + } + + let thread = searchResult.thread + SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose) + case .contacts: - sectionResults = searchResultSet.contacts + let sectionResults = searchResultSet.contacts + guard let searchResult = sectionResults[safe: indexPath.row] else { + owsFail("\(logTag) unknown row selected.") + return + } + + SignalApp.shared().presentConversation(forRecipientId: searchResult.recipientId, action: .compose) + case .messages: - sectionResults = searchResultSet.messages - } - - guard indexPath.row < sectionResults.count else { - owsFail("\(logTag) unknown row selected.") - return + let sectionResults = searchResultSet.messages + guard let searchResult = sectionResults[safe: indexPath.row] else { + owsFail("\(logTag) unknown row selected.") + return + } + + let thread = searchResult.thread + SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose) } - - let searchResult = sectionResults[indexPath.row] - let thread = searchResult.thread - SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose) } // MARK: UITableViewDataSource diff --git a/SignalMessaging/utils/ConversationSearcher.swift b/SignalMessaging/utils/ConversationSearcher.swift index f2ff4f53d..c38abd771 100644 --- a/SignalMessaging/utils/ConversationSearcher.swift +++ b/SignalMessaging/utils/ConversationSearcher.swift @@ -87,7 +87,7 @@ public class ConversationSearcher: NSObject { } } - // Only show contacts which were not included in an existing conversation. + // Only show contacts which were not included in an existing 1:1 conversation. let otherContacts: [ContactSearchResult] = contacts.filter { !existingConversationRecipientIds.contains($0.recipientId) } return SearchResultSet(conversations: conversations, contacts: otherContacts, messages: messages) diff --git a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift index c3d60a41d..c1db9378b 100644 --- a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift +++ b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift @@ -106,6 +106,12 @@ public class FullTextSearchFinder: NSObject { if let groupThread = object as? TSGroupThread { return self.groupThreadIndexer.index(groupThread) } else if let contactThread = object as? TSContactThread { + guard contactThread.hasEverHadMessage else { + // If we've never sent/received a message in a TSContactThread, + // then we want it to appear in the "Other Contacts" section rather + // than in the "Conversations" section. + return nil + } return self.contactThreadIndexer.index(contactThread) } else if let message = object as? TSMessage { return self.messageIndexer.index(message)