global: make sure we unsubscribe after each refresh
This commit is contained in:
@@ -35,9 +35,9 @@ class SearchHomeModel: ObservableObject {
|
||||
damus_state.pool.subscribe(sub_id: base_subid, filters: [get_base_filter()], handler: handle_event)
|
||||
}
|
||||
|
||||
func unsubscribe() {
|
||||
func unsubscribe(to: String? = nil) {
|
||||
loading = false
|
||||
damus_state.pool.unsubscribe(sub_id: base_subid)
|
||||
damus_state.pool.unsubscribe(sub_id: base_subid, to: to.map { [$0] })
|
||||
}
|
||||
|
||||
func handle_event(relay_id: String, conn_ev: NostrConnectionEvent) {
|
||||
@@ -65,9 +65,14 @@ class SearchHomeModel: ObservableObject {
|
||||
loading = false
|
||||
|
||||
if sub_id == self.base_subid {
|
||||
// Make sure we unsubscribe after we've fetched the global events
|
||||
// global events are not realtime
|
||||
unsubscribe(to: relay_id)
|
||||
|
||||
load_profiles(profiles_subid: profiles_subid, relay_id: relay_id, events: events, damus_state: damus_state)
|
||||
}
|
||||
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,11 @@ struct SearchHomeView: View {
|
||||
print("search change 1")
|
||||
}
|
||||
.onAppear {
|
||||
model.subscribe()
|
||||
// TODO: This will always be empty when switching between tabs
|
||||
// We'll need to store these in
|
||||
if model.events.isEmpty {
|
||||
model.subscribe()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
model.unsubscribe()
|
||||
|
||||
Reference in New Issue
Block a user