Hide blocked users from search results

Changelog-Fixed: Hide blocked users from search results
This commit is contained in:
William Casarin
2023-02-05 10:49:18 -08:00
parent 07676a1f95
commit 29a8206586
4 changed files with 17 additions and 4 deletions

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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.")

View File

@@ -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)
}