add note to self to the default global search screen with empty search text

pull/555/head
Ryan Zhao 3 years ago
parent 124d908686
commit 16f6d49cec

@ -12,7 +12,7 @@ class GlobalSearchViewController: BaseVC, UITableViewDelegate, UITableViewDataSo
refreshSearchResults()
}
}
var recentSearchResults: [String] = []
var recentSearchResults: [String] = Array(Storage.shared.getRecentSearchResults().reversed())
var searchResultSet: HomeScreenSearchResultSet = HomeScreenSearchResultSet.empty
private var lastSearchText: String?
var searcher: FullTextSearcher {
@ -98,7 +98,6 @@ class GlobalSearchViewController: BaseVC, UITableViewDelegate, UITableViewDataSo
}
private func reloadTableData() {
recentSearchResults = Array(Storage.shared.getRecentSearchResults().reversed())
tableView.reloadData()
}
@ -138,7 +137,7 @@ class GlobalSearchViewController: BaseVC, UITableViewDelegate, UITableViewDataSo
let searchText = rawSearchText.stripped
guard searchText.count > 0 else {
searchResultSet = HomeScreenSearchResultSet.empty
searchResultSet = HomeScreenSearchResultSet.noteToSelfOnly
lastSearchText = nil
reloadTableData()
return
@ -225,7 +224,7 @@ extension GlobalSearchViewController {
private func show(_ thread: TSThread, highlightedMessageID: String?, animated: Bool, isFromRecent: Bool = false) {
if let threadId = thread.uniqueId {
Storage.shared.addSearchResults(threadID: threadId)
recentSearchResults = Array(Storage.shared.addSearchResults(threadID: threadId).reversed())
}
DispatchMainThreadSafe {

@ -19,7 +19,7 @@ extension Storage{
}
}
public func addSearchResults(threadID: String) {
public func addSearchResults(threadID: String) -> [String] {
var recentSearchResults = getRecentSearchResults()
if recentSearchResults.count > 20 { recentSearchResults.remove(at: 0) } // Limit the size of the collection to 20
if let index = recentSearchResults.firstIndex(of: threadID) { recentSearchResults.remove(at: index) }
@ -27,5 +27,6 @@ extension Storage{
Storage.write { transaction in
transaction.setObject(recentSearchResults, forKey: Storage.recentSearchResultKey, inCollection: Storage.recentSearchResultDatabaseCollection)
}
return recentSearchResults
}
}

@ -65,6 +65,20 @@ public class HomeScreenSearchResultSet: NSObject {
public class var empty: HomeScreenSearchResultSet {
return HomeScreenSearchResultSet(searchText: "", conversations: [], messages: [])
}
public class var noteToSelfOnly: HomeScreenSearchResultSet {
var conversations: [ConversationSearchResult<ConversationSortKey>] = []
Storage.read { transaction in
if let thread = TSContactThread.getWithContactSessionID(getUserHexEncodedPublicKey(), transaction: transaction) {
let threadViewModel = ThreadViewModel(thread: thread, transaction: transaction)
let sortKey = ConversationSortKey(creationDate: thread.creationDate,
lastMessageReceivedAtDate: thread.lastInteractionForInbox(transaction: transaction)?.receivedAtDate())
let searchResult = ConversationSearchResult(thread: threadViewModel, sortKey: sortKey)
conversations.append(searchResult)
}
}
return HomeScreenSearchResultSet(searchText: "", conversations: conversations, messages: [])
}
public var isEmpty: Bool {
return conversations.isEmpty && messages.isEmpty

Loading…
Cancel
Save