damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit fe6d7e5118fb76ffd866ed589340c97a9880faed
parent 1367be0d10dc5224c14ed88e906ef5e05bcdb4d4
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 10 May 2023 12:20:33 -0700

relay: split descriptors to {our,all}_descriptors

Now that we have ephemeral relays, we don't want them used everywhere

Diffstat:
Mdamus/Components/ZapButton.swift | 2+-
Mdamus/ContentView.swift | 2+-
Mdamus/Nostr/RelayPool.swift | 6+++++-
Mdamus/Util/PostBox.swift | 2+-
Mdamus/Util/Relays/RelayFilters.swift | 2+-
Mdamus/Views/RelayFilterView.swift | 2+-
Mdamus/Views/Relays/RecommendedRelayView.swift | 2+-
Mdamus/Views/Relays/RelayConfigView.swift | 6+++---
Mdamus/Views/Relays/RelayDetailView.swift | 4++--
Mdamus/Views/Relays/RelayView.swift | 2+-
10 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/damus/Components/ZapButton.swift b/damus/Components/ZapButton.swift @@ -146,7 +146,7 @@ func send_zap(damus_state: DamusState, event: NostrEvent, lnurl: String, is_cust } // Only take the first 10 because reasons - let relays = Array(damus_state.pool.descriptors.prefix(10)) + let relays = Array(damus_state.pool.our_descriptors.prefix(10)) let target = ZapTarget.note(id: event.id, author: event.pubkey) let content = comment ?? "" diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -739,7 +739,7 @@ func find_event(state: DamusState, evid: String, search_type: SearchType, find_f case .eose: if !has_event { attempts += 1 - if attempts == state.pool.descriptors.count / 2 { + if attempts == state.pool.our_descriptors.count / 2 { callback(nil) } state.pool.unsubscribe(sub_id: subid, to: [relay_id]) diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift @@ -42,7 +42,11 @@ class RelayPool { network_monitor.start(queue: network_monitor_queue) } - var descriptors: [RelayDescriptor] { + var our_descriptors: [RelayDescriptor] { + return all_descriptors.filter { d in !d.info.ephemeral } + } + + var all_descriptors: [RelayDescriptor] { relays.map { r in r.descriptor } } diff --git a/damus/Util/PostBox.swift b/damus/Util/PostBox.swift @@ -105,7 +105,7 @@ class PostBox { return } - let remaining = to ?? pool.descriptors.map { $0.url.id } + let remaining = to ?? pool.our_descriptors.map { $0.url.id } let posted_ev = PostedEvent(event: event, remaining: remaining, skip_ephemeral: skip_ephemeral) events[event.id] = posted_ev diff --git a/damus/Util/Relays/RelayFilters.swift b/damus/Util/Relays/RelayFilters.swift @@ -83,7 +83,7 @@ func load_relay_filters(_ pubkey: String) -> Set<RelayFilter>? { } func determine_to_relays(pool: RelayPool, filters: RelayFilters) -> [String] { - return pool.descriptors + return pool.our_descriptors .map { $0.url.url.absoluteString } .filter { !filters.is_filtered(timeline: .search, relay_id: $0) } } diff --git a/damus/Views/RelayFilterView.swift b/damus/Views/RelayFilterView.swift @@ -22,7 +22,7 @@ struct RelayFilterView: View { } var relays: [RelayDescriptor] { - return state.pool.descriptors + return state.pool.our_descriptors } var body: some View { diff --git a/damus/Views/Relays/RecommendedRelayView.swift b/damus/Views/Relays/RecommendedRelayView.swift @@ -107,7 +107,7 @@ struct RecommendedRelayView: View { guard let ev_before_add = damus.contacts.event else { return } - guard let ev_after_add = add_relay(ev: ev_before_add, privkey: privkey, current_relays: damus.pool.descriptors, relay: relay, info: .rw) else { + guard let ev_after_add = add_relay(ev: ev_before_add, privkey: privkey, current_relays: damus.pool.our_descriptors, relay: relay, info: .rw) else { return } process_contact_event(state: damus, ev: ev_after_add) diff --git a/damus/Views/Relays/RelayConfigView.swift b/damus/Views/Relays/RelayConfigView.swift @@ -17,7 +17,7 @@ struct RelayConfigView: View { init(state: DamusState) { self.state = state - _relays = State(initialValue: state.pool.descriptors) + _relays = State(initialValue: state.pool.our_descriptors) } var recommended: [RelayDescriptor] { @@ -32,7 +32,7 @@ struct RelayConfigView: View { var body: some View { MainContent .onReceive(handle_notify(.relays_changed)) { _ in - self.relays = state.pool.descriptors + self.relays = state.pool.our_descriptors } .onReceive(handle_notify(.switched_timeline)) { _ in dismiss() @@ -95,7 +95,7 @@ struct RelayConfigView: View { state.pool.connect(to: [new_relay]) - guard let new_ev = add_relay(ev: ev, privkey: privkey, current_relays: state.pool.descriptors, relay: new_relay, info: info) else { + guard let new_ev = add_relay(ev: ev, privkey: privkey, current_relays: state.pool.our_descriptors, relay: new_relay, info: info) else { return } diff --git a/damus/Views/Relays/RelayDetailView.swift b/damus/Views/Relays/RelayDetailView.swift @@ -38,7 +38,7 @@ struct RelayDetailView: View { return } - let descriptors = state.pool.descriptors + let descriptors = state.pool.our_descriptors guard let new_ev = remove_relay( ev: ev, current_relays: descriptors, privkey: privkey, relay: relay) else { return } @@ -54,7 +54,7 @@ struct RelayDetailView: View { guard let ev_before_add = state.contacts.event else { return } - guard let ev_after_add = add_relay(ev: ev_before_add, privkey: privkey, current_relays: state.pool.descriptors, relay: relay, info: .rw) else { + guard let ev_after_add = add_relay(ev: ev_before_add, privkey: privkey, current_relays: state.pool.our_descriptors, relay: relay, info: .rw) else { return } process_contact_event(state: state, ev: ev_after_add) diff --git a/damus/Views/Relays/RelayView.swift b/damus/Views/Relays/RelayView.swift @@ -76,7 +76,7 @@ struct RelayView: View { return } - let descriptors = state.pool.descriptors + let descriptors = state.pool.our_descriptors guard let new_ev = remove_relay( ev: ev, current_relays: descriptors, privkey: privkey, relay: relay) else { return }