Compare commits
No commits in common. "5cef76e4948d981fa4d8aaec93e7311de0cdcb9c" and "32b8d2794957d444d53a24815fa637bf4ddc0fb7" have entirely different histories.
5cef76e494
...
32b8d27949
|
@ -88,7 +88,7 @@ class MastodonSearchController: UISearchController {
|
|||
if searchText.isEmpty || "from:me".contains(searchText) {
|
||||
fromSuggestions.append("from:me")
|
||||
}
|
||||
if searchText != "me" && searchText != "from:me",
|
||||
if searchText != "me",
|
||||
let match = acctRegex.firstMatch(in: searchText, range: NSRange(location: 0, length: searchText.utf16.count)) {
|
||||
let matched = (searchText as NSString).substring(with: match.range)
|
||||
fromSuggestions.append("from:\(matched)")
|
||||
|
|
|
@ -46,7 +46,6 @@ class SearchResultsViewController: UIViewController, CollectionViewController {
|
|||
private let searchSubject = PassthroughSubject<String?, Never>()
|
||||
private var searchCancellable: AnyCancellable?
|
||||
private var currentQuery: String?
|
||||
private var currentSearchResults: SearchResults?
|
||||
|
||||
init(mastodonController: MastodonController, scope: Scope = .all) {
|
||||
self.mastodonController = mastodonController
|
||||
|
@ -261,14 +260,7 @@ class SearchResultsViewController: UIViewController, CollectionViewController {
|
|||
switch response {
|
||||
case let .success(results, _):
|
||||
guard self.currentQuery == query else { return }
|
||||
self.mastodonController.persistentContainer.performBatchUpdates { (context, addAccounts, addStatuses) in
|
||||
addAccounts(results.accounts)
|
||||
addStatuses(results.statuses)
|
||||
} completion: {
|
||||
DispatchQueue.main.async {
|
||||
self.showSearchResults(results)
|
||||
}
|
||||
}
|
||||
case let .failure(error):
|
||||
DispatchQueue.main.async {
|
||||
self.showSearchError(error)
|
||||
|
@ -277,18 +269,16 @@ class SearchResultsViewController: UIViewController, CollectionViewController {
|
|||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func showSearchResults(_ results: SearchResults) {
|
||||
self.currentSearchResults = results
|
||||
|
||||
var snapshot = dataSource.snapshot()
|
||||
snapshot.deleteSections([.loadingIndicator])
|
||||
removeResults(from: &snapshot)
|
||||
|
||||
self.mastodonController.persistentContainer.performBatchUpdates({ (context, addAccounts, addStatuses) in
|
||||
let resultTypes = self.scope.resultTypes
|
||||
if !results.accounts.isEmpty && resultTypes.contains(.accounts) {
|
||||
snapshot.appendSections([.accounts])
|
||||
snapshot.appendItems(results.accounts.map { .account($0.id) }, toSection: .accounts)
|
||||
addAccounts(results.accounts)
|
||||
}
|
||||
if !results.hashtags.isEmpty && resultTypes.contains(.hashtags) {
|
||||
snapshot.appendSections([.hashtags])
|
||||
|
@ -297,9 +287,13 @@ class SearchResultsViewController: UIViewController, CollectionViewController {
|
|||
if !results.statuses.isEmpty && resultTypes.contains(.statuses) {
|
||||
snapshot.appendSections([.statuses])
|
||||
snapshot.appendItems(results.statuses.map { .status($0.id, .unknown) }, toSection: .statuses)
|
||||
addStatuses(results.statuses)
|
||||
}
|
||||
|
||||
dataSource.apply(snapshot)
|
||||
}, completion: {
|
||||
DispatchQueue.main.async {
|
||||
self.dataSource.apply(snapshot)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private func showSearchError(_ error: Client.Error) {
|
||||
|
@ -569,9 +563,7 @@ extension SearchResultsViewController: UISearchBarDelegate {
|
|||
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
|
||||
let newQuery = searchBar.searchQueryWithOperators
|
||||
let newScope = Scope.allCases[selectedScope]
|
||||
if currentQuery == newQuery,
|
||||
let currentSearchResults {
|
||||
if self.scope == .all {
|
||||
if self.scope == .all && currentQuery == newQuery {
|
||||
self.scope = newScope
|
||||
var snapshot = dataSource.snapshot()
|
||||
if snapshot.sectionIdentifiers.contains(.accounts) && scope != .people {
|
||||
|
@ -584,10 +576,6 @@ extension SearchResultsViewController: UISearchBarDelegate {
|
|||
snapshot.deleteSections([.statuses])
|
||||
}
|
||||
dataSource.apply(snapshot)
|
||||
} else {
|
||||
self.scope = newScope
|
||||
showSearchResults(currentSearchResults)
|
||||
}
|
||||
} else {
|
||||
self.scope = newScope
|
||||
performSearch(query: newQuery)
|
||||
|
|
Loading…
Reference in New Issue