|
|
|
@ -27,6 +27,8 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lastQuery: String = ""
|
|
|
|
|
|
|
|
|
|
public weak var delegate: GifPickerViewControllerDelegate?
|
|
|
|
|
|
|
|
|
|
var thread: TSThread?
|
|
|
|
@ -370,6 +372,8 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
|
|
|
|
|
self.searchBar.resignFirstResponder()
|
|
|
|
|
|
|
|
|
|
tryToSearch()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -384,7 +388,15 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|
|
|
|
comment: "Alert message shown when user tries to search for GIFs without entering any search terms."))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
search(query:text)
|
|
|
|
|
|
|
|
|
|
let query = (text as String).trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
|
|
|
|
|
|
|
|
|
if (viewMode == .searching || viewMode == .results) && lastQuery == query {
|
|
|
|
|
Logger.info("\(TAG) ignoring duplicate search: \(query)")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
search(query: query)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func search(query: String) {
|
|
|
|
@ -392,9 +404,9 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|
|
|
|
|
|
|
|
|
progressiveSearchTimer?.invalidate()
|
|
|
|
|
progressiveSearchTimer = nil
|
|
|
|
|
self.searchBar.resignFirstResponder()
|
|
|
|
|
imageInfos = []
|
|
|
|
|
viewMode = .searching
|
|
|
|
|
lastQuery = query
|
|
|
|
|
self.collectionView.contentOffset = CGPoint.zero
|
|
|
|
|
|
|
|
|
|
GiphyAPI.sharedInstance.search(query: query, success: { [weak self] imageInfos in
|
|
|
|
|