commit f7946b1a7ce8c73ef9f75c6802d9809399f300ea
parent 84cfeb16048c6387a38eaac5d1fbf1a1d1762a13
Author: Charlie Fish <contact@charlie.fish>
Date: Sun, 7 Jan 2024 11:17:59 -0700
relay: fix case where content is empty when adding relay
Lightning-Address: fishcharlie@strike.me
Closes: https://github.com/damus-io/damus/issues/1849
Signed-off-by: Charlie Fish <contact@charlie.fish>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Changelog-Fixed: Fix issue where adding relays might not work on corrupted contact lists
Diffstat:
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/damus/Models/Contacts.swift b/damus/Models/Contacts.swift
@@ -203,8 +203,8 @@ func remove_relay(ev: NostrEvent, current_relays: [RelayDescriptor], keypair: Fu
func add_relay(ev: NostrEvent, keypair: FullKeypair, current_relays: [RelayDescriptor], relay: RelayURL, info: RelayInfo) -> NostrEvent? {
var relays = ensure_relay_info(relays: current_relays, content: ev.content)
-
- guard relays.index(forKey: relay) == nil else {
+ // If kind:3 content is empty, or if the relay doesn't exist in the list, we want to create a kind:3 event with the new relay
+ guard ev.content.isEmpty || relays.index(forKey: relay) == nil else {
return nil
}
diff --git a/damus/Views/AddRelayView.swift b/damus/Views/AddRelayView.swift
@@ -105,13 +105,11 @@ struct AddRelayView: View {
state.pool.connect(to: [new_relay])
- guard let new_ev = add_relay(ev: ev, keypair: keypair, current_relays: state.pool.our_descriptors, relay: url, info: info) else {
- return
- }
+ if let new_ev = add_relay(ev: ev, keypair: keypair, current_relays: state.pool.our_descriptors, relay: url, info: info) {
+ process_contact_event(state: state, ev: ev)
- process_contact_event(state: state, ev: ev)
-
- state.pool.send(.event(new_ev))
+ state.pool.send(.event(new_ev))
+ }
if let relay_metadata = make_relay_metadata(relays: state.pool.our_descriptors, keypair: keypair) {
state.postbox.send(relay_metadata)