commit 4f459d128a5761143c4ec71af63b56091c95a46b
parent 58e53631c6cae241c0105cc8c78e84eaf502cf9d
Author: William Casarin <jb55@jb55.com>
Date: Tue, 2 May 2023 07:50:28 -0700
Load profiles in hashtag searches
Changelog-Fixed: Load profiles in hashtag searched
Diffstat:
4 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -206,7 +206,7 @@ struct ContentView: View {
var MaybeSearchView: some View {
Group {
if let search = self.active_search {
- SearchView(appstate: damus_state!, search: SearchModel(contacts: damus_state!.contacts, pool: damus_state!.pool, search: search))
+ SearchView(appstate: damus_state!, search: SearchModel(state: damus_state!, search: search))
} else {
EmptyView()
}
diff --git a/damus/Models/SearchModel.swift b/damus/Models/SearchModel.swift
@@ -9,24 +9,23 @@ import Foundation
class SearchModel: ObservableObject {
+ let state: DamusState
var events: EventHolder = EventHolder()
@Published var loading: Bool = false
@Published var channel_name: String? = nil
- let pool: RelayPool
var search: NostrFilter
- let contacts: Contacts
let sub_id = UUID().description
+ let profiles_subid = UUID().description
let limit: UInt32 = 500
- init(contacts: Contacts, pool: RelayPool, search: NostrFilter) {
- self.contacts = contacts
- self.pool = pool
+ init(state: DamusState, search: NostrFilter) {
+ self.state = state
self.search = search
}
func filter_muted() {
- self.events.filter { should_show_event(contacts: contacts, ev: $0) }
+ self.events.filter { should_show_event(contacts: state.contacts, ev: $0) }
self.objectWillChange.send()
}
@@ -38,13 +37,13 @@ class SearchModel: ObservableObject {
//likes_filter.ids = ref_events.referenced_ids!
print("subscribing to search '\(search)' with sub_id \(sub_id)")
- pool.register_handler(sub_id: sub_id, handler: handle_event)
+ state.pool.register_handler(sub_id: sub_id, handler: handle_event)
loading = true
- pool.send(.subscribe(.init(filters: [search], sub_id: sub_id)))
+ state.pool.send(.subscribe(.init(filters: [search], sub_id: sub_id)))
}
func unsubscribe() {
- self.pool.unsubscribe(sub_id: sub_id)
+ state.pool.unsubscribe(sub_id: sub_id)
loading = false
print("unsubscribing from search '\(search)' with sub_id \(sub_id)")
}
@@ -54,7 +53,7 @@ class SearchModel: ObservableObject {
return
}
- guard should_show_event(contacts: contacts, ev: ev) else {
+ guard should_show_event(contacts: state.contacts, ev: ev) else {
return
}
@@ -74,7 +73,7 @@ class SearchModel: ObservableObject {
}
func handle_event(relay_id: String, ev: NostrConnectionEvent) {
- let (_, done) = handle_subid_event(pool: pool, relay_id: relay_id, ev: ev) { sub_id, ev in
+ let (sub_id, done) = handle_subid_event(pool: state.pool, relay_id: relay_id, ev: ev) { sub_id, ev in
if ev.is_textlike && ev.should_show_event {
self.add_event(ev)
} else if ev.known_kind == .channel_create {
@@ -84,8 +83,12 @@ class SearchModel: ObservableObject {
}
}
- if done {
- loading = false
+ guard done else {
+ return
+ }
+
+ if sub_id == self.sub_id {
+ load_profiles(profiles_subid: self.profiles_subid, relay_id: relay_id, load: .from_events(self.events.all_events), damus_state: state)
}
}
}
diff --git a/damus/Views/SearchResultsView.swift b/damus/Views/SearchResultsView.swift
@@ -37,7 +37,7 @@ struct SearchResultsView: View {
}
}
case .hashtag(let ht):
- let search_model = SearchModel(contacts: damus_state.contacts, pool: damus_state.pool, search: .filter_hashtag([ht]))
+ let search_model = SearchModel(state: damus_state, 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
@@ -43,9 +43,8 @@ struct SearchView_Previews: PreviewProvider {
static var previews: some View {
let test_state = test_damus_state()
let filter = NostrFilter.filter_hashtag(["bitcoin"])
- let pool = test_state.pool
- let model = SearchModel(contacts: test_state.contacts, pool: pool, search: filter)
+ let model = SearchModel(state: test_state, search: filter)
SearchView(appstate: test_state, search: model)
}