mirror of https://github.com/oxen-io/session-ios
WIP: FTS - wired up Search VC
-[] Backend -[] indexes e5.25 -[x] wire up results: Contacts / Conversations / Messages actual: 3hr -[ ] group thread est: actual: -[x] group name actual: e.25 -[ ] group member name: e.25 -[ ] group member number: e.25 -[ ] contact thread e.5 -[ ] name -[ ] number -[ ] messages e1 -[ ] content -[] Frontend e10.75 -[x] wire up VC's a.5 -[x] show search results only when search box has content a.25 -[] show search results: Contact / Conversation / Messages e2 -[] tapping thread search result takes you to conversation e1 -[] tapping message search result takes you to message e1 -[] show snippet text for matched message e1 -[] highlight matched text in thread e3 -[] go to next search result in thread e2pull/1/head
parent
429af7854a
commit
ffea3a020f
@ -0,0 +1,148 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@objc
|
||||||
|
class ConversationSearchViewController: UITableViewController {
|
||||||
|
|
||||||
|
var searchResults: ConversationSearchResults = ConversationSearchResults.empty()
|
||||||
|
|
||||||
|
enum SearchSection: Int {
|
||||||
|
case conversations = 0
|
||||||
|
case contacts = 1
|
||||||
|
case messages = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: View Lifecyle
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
self.view.isHidden = true
|
||||||
|
self.view.backgroundColor = UIColor.yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: UITableViewDelegate
|
||||||
|
|
||||||
|
override public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
guard let searchSection = SearchSection(rawValue: section) else {
|
||||||
|
owsFail("unknown section: \(section)")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
switch searchSection {
|
||||||
|
case .conversations:
|
||||||
|
return searchResults.conversations.count
|
||||||
|
case .contacts:
|
||||||
|
return searchResults.contacts.count
|
||||||
|
case .messages:
|
||||||
|
return searchResults.messages.count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
|
||||||
|
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
|
||||||
|
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
|
||||||
|
|
||||||
|
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func numberOfSections(in tableView: UITableView) -> Int // Default is 1 if not implemented
|
||||||
|
|
||||||
|
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? // fixed font style. use custom view (UILabel) if you want something different
|
||||||
|
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
|
||||||
|
|
||||||
|
|
||||||
|
// Editing
|
||||||
|
|
||||||
|
// Individual rows can opt out of having the -editing property set for them. If not implemented, all rows are assumed to be editable.
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
|
||||||
|
|
||||||
|
|
||||||
|
// Moving/reordering
|
||||||
|
|
||||||
|
// Allows the reorder accessory view to optionally be shown for a particular row. By default, the reorder control will be shown only if the datasource implements -tableView:moveRowAtIndexPath:toIndexPath:
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool
|
||||||
|
|
||||||
|
|
||||||
|
// Index
|
||||||
|
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func sectionIndexTitles(for tableView: UITableView) -> [String]? // return list of section titles to display in section index view (e.g. "ABCD...Z#")
|
||||||
|
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int // tell table which section corresponds to section title/index (e.g. "B",1))
|
||||||
|
|
||||||
|
|
||||||
|
// Data manipulation - insert and delete support
|
||||||
|
|
||||||
|
// After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change
|
||||||
|
// Not called for edit actions using UITableViewRowAction - the action's handler will be invoked instead
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
|
||||||
|
|
||||||
|
|
||||||
|
// Data manipulation - reorder / moving support
|
||||||
|
|
||||||
|
@available(iOS 2.0, *)
|
||||||
|
optional public func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ConversationSearchViewController: UISearchBarDelegate {
|
||||||
|
// @available(iOS 2.0, *)
|
||||||
|
// optional public func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool // return NO to not become first responder
|
||||||
|
//
|
||||||
|
// @available(iOS 2.0, *)
|
||||||
|
// optional public func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) // called when text starts editing
|
||||||
|
//
|
||||||
|
// @available(iOS 2.0, *)
|
||||||
|
// optional public func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool // return NO to not resign first responder
|
||||||
|
//
|
||||||
|
// @available(iOS 2.0, *)
|
||||||
|
// optional public func searchBarTextDidEndEditing(_ searchBar: UISearchBar) // called when text ends editing
|
||||||
|
//
|
||||||
|
|
||||||
|
public func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
|
||||||
|
guard searchText.stripped.count > 0 else {
|
||||||
|
self.view.isHidden = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.view.isHidden = false
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// @available(iOS 3.0, *)
|
||||||
|
// optional public func searchBar(_ searchBar: UISearchBar, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool // called before text changes
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// @available(iOS 2.0, *)
|
||||||
|
// optional public func searchBarSearchButtonClicked(_ searchBar: UISearchBar) // called when keyboard search button pressed
|
||||||
|
//
|
||||||
|
// @available(iOS 2.0, *)
|
||||||
|
// optional public func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) // called when bookmark button pressed
|
||||||
|
//
|
||||||
|
// @available(iOS 2.0, *)
|
||||||
|
// optional public func searchBarCancelButtonClicked(_ searchBar: UISearchBar) // called when cancel button pressed
|
||||||
|
//
|
||||||
|
// @available(iOS 3.2, *)
|
||||||
|
// optional public func searchBarResultsListButtonClicked(_ searchBar: UISearchBar) // called when search results button pressed
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// @available(iOS 3.0, *)
|
||||||
|
// optional public func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int)
|
||||||
|
}
|
Loading…
Reference in New Issue