global: make sure we unsubscribe after each refresh

This commit is contained in:
William Casarin
2022-12-21 12:50:18 -08:00
parent b1d14ff21f
commit 37460f933b
2 changed files with 12 additions and 3 deletions

View File

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

View File

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