commit 37460f933b2d0505322de8c27593d28a8c36f463
parent b1d14ff21f7d68b8eb8358993ef90af18651d37b
Author: William Casarin <jb55@jb55.com>
Date: Wed, 21 Dec 2022 12:50:18 -0800
global: make sure we unsubscribe after each refresh
Diffstat:
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift
@@ -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
}
}
diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift
@@ -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()