damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 29a82065868e1c72fe12b19f8d2ac8e7f345a964
parent 07676a1f95e8b2f7b84d0ea0554695d66736960d
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  5 Feb 2023 10:49:18 -0800

Hide blocked users from search results

Changelog-Fixed: Hide blocked users from search results

Diffstat:
Mdamus/ContentView.swift | 2+-
Mdamus/Models/SearchModel.swift | 12+++++++++++-
Mdamus/Views/SearchResultsView.swift | 2+-
Mdamus/Views/SearchView.swift | 5++++-
4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -197,7 +197,7 @@ struct ContentView: View { var MaybeSearchView: some View { Group { if let search = self.active_search { - SearchView(appstate: damus_state!, search: SearchModel(pool: damus_state!.pool, search: search)) + SearchView(appstate: damus_state!, search: SearchModel(contacts: damus_state!.contacts, pool: damus_state!.pool, search: search)) } else { EmptyView() } diff --git a/damus/Models/SearchModel.swift b/damus/Models/SearchModel.swift @@ -15,14 +15,20 @@ class SearchModel: ObservableObject { let pool: RelayPool var search: NostrFilter + let contacts: Contacts let sub_id = UUID().description let limit: UInt32 = 500 - init(pool: RelayPool, search: NostrFilter) { + init(contacts: Contacts, pool: RelayPool, search: NostrFilter) { + self.contacts = contacts self.pool = pool self.search = search } + func filter_muted() { + self.events = self.events.filter { should_show_event(contacts: contacts, ev: $0) } + } + func subscribe() { // since 1 month search.limit = self.limit @@ -47,6 +53,10 @@ class SearchModel: ObservableObject { return } + guard should_show_event(contacts: contacts, ev: ev) else { + return + } + if insert_uniq_sorted_event(events: &self.events, new_ev: ev, cmp: { $0.created_at > $1.created_at } ) { objectWillChange.send() } diff --git a/damus/Views/SearchResultsView.swift b/damus/Views/SearchResultsView.swift @@ -35,7 +35,7 @@ struct SearchResultsView: View { } } case .hashtag(let ht): - let search_model = SearchModel(pool: damus_state.pool, search: .filter_hashtag([ht])) + let search_model = SearchModel(contacts: damus_state.contacts, pool: damus_state.pool, search: .filter_hashtag([ht])) let dst = SearchView(appstate: damus_state, search: search_model) NavigationLink(destination: dst) { Text("Search hashtag: #\(ht)", comment: "Navigation link to search hashtag.") diff --git a/damus/Views/SearchView.swift b/damus/Views/SearchView.swift @@ -25,6 +25,9 @@ struct SearchView: View { .onDisappear() { search.unsubscribe() } + .onReceive(handle_notify(.new_mutes)) { notif in + search.filter_muted() + } } } @@ -43,7 +46,7 @@ struct SearchView_Previews: PreviewProvider { let filter = NostrFilter.filter_hashtag(["bitcoin"]) let pool = test_state.pool - let model = SearchModel(pool: pool, search: filter) + let model = SearchModel(contacts: test_state.contacts, pool: pool, search: filter) SearchView(appstate: test_state, search: model) }