Hide blocked users from search results
Changelog-Fixed: Hide blocked users from search results
This commit is contained in:
@@ -197,7 +197,7 @@ struct ContentView: View {
|
|||||||
var MaybeSearchView: some View {
|
var MaybeSearchView: some View {
|
||||||
Group {
|
Group {
|
||||||
if let search = self.active_search {
|
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 {
|
} else {
|
||||||
EmptyView()
|
EmptyView()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,20 @@ class SearchModel: ObservableObject {
|
|||||||
|
|
||||||
let pool: RelayPool
|
let pool: RelayPool
|
||||||
var search: NostrFilter
|
var search: NostrFilter
|
||||||
|
let contacts: Contacts
|
||||||
let sub_id = UUID().description
|
let sub_id = UUID().description
|
||||||
let limit: UInt32 = 500
|
let limit: UInt32 = 500
|
||||||
|
|
||||||
init(pool: RelayPool, search: NostrFilter) {
|
init(contacts: Contacts, pool: RelayPool, search: NostrFilter) {
|
||||||
|
self.contacts = contacts
|
||||||
self.pool = pool
|
self.pool = pool
|
||||||
self.search = search
|
self.search = search
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filter_muted() {
|
||||||
|
self.events = self.events.filter { should_show_event(contacts: contacts, ev: $0) }
|
||||||
|
}
|
||||||
|
|
||||||
func subscribe() {
|
func subscribe() {
|
||||||
// since 1 month
|
// since 1 month
|
||||||
search.limit = self.limit
|
search.limit = self.limit
|
||||||
@@ -47,6 +53,10 @@ class SearchModel: ObservableObject {
|
|||||||
return
|
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 } ) {
|
if insert_uniq_sorted_event(events: &self.events, new_ev: ev, cmp: { $0.created_at > $1.created_at } ) {
|
||||||
objectWillChange.send()
|
objectWillChange.send()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ struct SearchResultsView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .hashtag(let ht):
|
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)
|
let dst = SearchView(appstate: damus_state, search: search_model)
|
||||||
NavigationLink(destination: dst) {
|
NavigationLink(destination: dst) {
|
||||||
Text("Search hashtag: #\(ht)", comment: "Navigation link to search hashtag.")
|
Text("Search hashtag: #\(ht)", comment: "Navigation link to search hashtag.")
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ struct SearchView: View {
|
|||||||
.onDisappear() {
|
.onDisappear() {
|
||||||
search.unsubscribe()
|
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 filter = NostrFilter.filter_hashtag(["bitcoin"])
|
||||||
let pool = test_state.pool
|
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)
|
SearchView(appstate: test_state, search: model)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user