From 37460f933b2d0505322de8c27593d28a8c36f463 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 21 Dec 2022 12:50:18 -0800 Subject: [PATCH] global: make sure we unsubscribe after each refresh --- damus/Models/SearchHomeModel.swift | 9 +++++++-- damus/Views/SearchHomeView.swift | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift index 617cd76..9783c5c 100644 --- 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 index 74da505..f68bec0 100644 --- 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()