From f8dc9f42dd49171998260dcb2aabcca6f5a6fe89 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 26 Dec 2022 07:37:42 -0800 Subject: [PATCH] Fix profile and event loading in global view Changelog-Fixed: Fix profile and event loading in global view --- damus/Nostr/RelayPool.swift | 17 +++++++++++++---- damus/Views/SearchHomeView.swift | 2 -- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift index f38a2a9d..aa797142 100644 --- a/damus/Nostr/RelayPool.swift +++ b/damus/Nostr/RelayPool.swift @@ -41,12 +41,19 @@ class RelayPool { } func remove_handler(sub_id: String) { - handlers = handlers.filter { $0.sub_id != sub_id } + self.handlers = handlers.filter { $0.sub_id != sub_id } + print("removing \(sub_id) handler, current: \(handlers.count)") } func register_handler(sub_id: String, handler: @escaping (String, NostrConnectionEvent) -> ()) { - + for handler in handlers { + // don't add duplicate handlers + if handler.sub_id == sub_id { + return + } + } self.handlers.append(RelayHandler(sub_id: sub_id, callback: handler)) + print("registering \(sub_id) handler, current: \(self.handlers.count)") } func remove_relay(_ relay_id: String) { @@ -125,8 +132,10 @@ class RelayPool { } func unsubscribe(sub_id: String, to: [String]? = nil) { - self.remove_handler(sub_id: sub_id) - self.send(.unsubscribe(sub_id)) + if to == nil { + self.remove_handler(sub_id: sub_id) + } + self.send(.unsubscribe(sub_id), to: to) } func subscribe(sub_id: String, filters: [NostrFilter], handler: @escaping (String, NostrConnectionEvent) -> ()) { diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift index 27fae882..71c3bfda 100644 --- a/damus/Views/SearchHomeView.swift +++ b/damus/Views/SearchHomeView.swift @@ -85,8 +85,6 @@ struct SearchHomeView: View { print("search change 1") } .onAppear { - // TODO: This will always be empty when switching between tabs - // We'll need to store these in if model.events.isEmpty { model.subscribe() }