@ -5,7 +5,7 @@
import Foundation
@objc
class ConversationSearchViewController : UITableViewController {
class ConversationSearchViewController : UITableViewController , UISearchBarDelegate {
var searchResultSet : SearchResultSet = SearchResultSet . empty
@ -122,52 +122,20 @@ class ConversationSearchViewController: UITableViewController {
}
}
/*
@ available ( iOS 2.0 , * )
optional public func tableView ( _ tableView : UITableView , titleForFooterInSection section : Int ) -> String ?
// MARK: U I S e a r c h B a r D e l e g a t e
@objc
public var searchBar : UISearchBar ?
// E d i t i n g
// I n d i v i d u a l r o w s c a n o p t o u t o f h a v i n g t h e - e d i t i n g p r o p e r t y s e t f o r t h e m . I f n o t i m p l e m e n t e d , a l l r o w s a r e a s s u m e d t o b e e d i t a b l e .
@ available ( iOS 2.0 , * )
optional public func tableView ( _ tableView : UITableView , canEditRowAt indexPath : IndexPath ) -> Bool
// M o v i n g / r e o r d e r i n g
// A l l o w s t h e r e o r d e r a c c e s s o r y v i e w t o o p t i o n a l l y b e s h o w n f o r a p a r t i c u l a r r o w . B y d e f a u l t , t h e r e o r d e r c o n t r o l w i l l b e s h o w n o n l y i f t h e d a t a s o u r c e i m p l e m e n t s - t a b l e V i e w : m o v e R o w A t I n d e x P a t h : t o I n d e x P a t h :
@ available ( iOS 2.0 , * )
optional public func tableView ( _ tableView : UITableView , canMoveRowAt indexPath : IndexPath ) -> Bool
// I n d e x
@ available ( iOS 2.0 , * )
optional public func sectionIndexTitles ( for tableView : UITableView ) -> [ String ] ? // r e t u r n l i s t o f s e c t i o n t i t l e s t o d i s p l a y i n s e c t i o n i n d e x v i e w ( e . g . " A B C D . . . Z # " )
@ available ( iOS 2.0 , * )
optional public func tableView ( _ tableView : UITableView , sectionForSectionIndexTitle title : String , at index : Int ) -> Int // t e l l t a b l e w h i c h s e c t i o n c o r r e s p o n d s t o s e c t i o n t i t l e / i n d e x ( e . g . " B " , 1 ) )
// D a t a m a n i p u l a t i o n - i n s e r t a n d d e l e t e s u p p o r t
// A f t e r a r o w h a s t h e m i n u s o r p l u s b u t t o n i n v o k e d ( b a s e d o n t h e U I T a b l e V i e w C e l l E d i t i n g S t y l e f o r t h e c e l l ) , t h e d a t a S o u r c e m u s t c o m m i t t h e c h a n g e
// N o t c a l l e d f o r e d i t a c t i o n s u s i n g U I T a b l e V i e w R o w A c t i o n - t h e a c t i o n ' s h a n d l e r w i l l b e i n v o k e d i n s t e a d
@ available ( iOS 2.0 , * )
optional public func tableView ( _ tableView : UITableView , commit editingStyle : UITableViewCellEditingStyle , forRowAt indexPath : IndexPath )
// D a t a m a n i p u l a t i o n - r e o r d e r / m o v i n g s u p p o r t
@ available ( iOS 2.0 , * )
optional public func tableView ( _ tableView : UITableView , moveRowAt sourceIndexPath : IndexPath , to destinationIndexPath : IndexPath )
*/
override func scrollViewWillBeginDragging ( _ scrollView : UIScrollView ) {
guard let searchBar = self . searchBar else {
owsFail ( " \( logTag ) searchBar was unexpectedly nil " )
return
}
searchBar . resignFirstResponder ( )
}
extension ConversationSearchViewController : UISearchBarDelegate {
public func searchBar ( _ searchBar : UISearchBar , textDidChange searchText : String ) {
guard searchText . stripped . count > 0 else {
self . searchResultSet = SearchResultSet . empty
@ -193,15 +161,19 @@ class ChatSearchResultCell: UITableViewCell {
let nameLabel : UILabel
let snippetLabel : UILabel
let avatarView : AvatarImageView
let avatarWidth : UInt = 40
override init ( style : UITableViewCellStyle , reuseIdentifier : String ? ) {
self . nameLabel = UILabel ( )
self . snippetLabel = UILabel ( )
self . avatarView = AvatarImageView ( )
avatarView . autoSetDimensions ( to : CGSize ( width : 40 , height : 40 ) )
avatarView . autoSetDimensions ( to : CGSize ( width : CGFloat ( avatarWidth ) , height : CGFloat ( avatarWidth ) ) )
super . init ( style : style , reuseIdentifier : reuseIdentifier )
nameLabel . font = UIFont . ows_dynamicTypeBody . ows_mediumWeight ( )
snippetLabel . font = UIFont . ows_dynamicTypeFootnote
let textRows = UIStackView ( arrangedSubviews : [ nameLabel , snippetLabel ] )
textRows . axis = . vertical
@ -217,7 +189,12 @@ class ChatSearchResultCell: UITableViewCell {
fatalError ( " init(coder:) has not been implemented " )
}
var contactsManager : OWSContactsManager {
return Environment . current ( ) . contactsManager
}
func configure ( searchResult : SearchResult ) {
self . avatarView . image = OWSAvatarBuilder . buildImage ( thread : searchResult . thread . threadRecord , diameter : avatarWidth , contactsManager : self . contactsManager )
self . nameLabel . text = searchResult . thread . name
self . snippetLabel . text = searchResult . snippet
}
@ -235,6 +212,9 @@ class MessageSearchResultCell: UITableViewCell {
super . init ( style : style , reuseIdentifier : reuseIdentifier )
nameLabel . font = UIFont . ows_dynamicTypeBody . ows_mediumWeight ( )
snippetLabel . font = UIFont . ows_dynamicTypeFootnote
let textRows = UIStackView ( arrangedSubviews : [ nameLabel , snippetLabel ] )
textRows . axis = . vertical
@ -261,9 +241,12 @@ class MessageSearchResultCell: UITableViewCell {
// B o l d s n i p p e t t e x t
do {
let attributedSnippet = try NSAttributedString ( data : encodedString ,
// F I X M E - a p p l y o u r f o n t w i t h o u t c l o b b e r i n g b o l d .
let attributedSnippet = try NSMutableAttributedString ( data : encodedString ,
options : [ NSAttributedString . DocumentReadingOptionKey . documentType : NSAttributedString . DocumentType . html ] ,
documentAttributes : nil )
attributedSnippet . addAttribute ( NSAttributedStringKey . font , value : self . snippetLabel . font , range : NSRange ( location : 0 , length : attributedSnippet . length ) )
self . snippetLabel . attributedText = attributedSnippet
} catch {