commit 7a5aef94a8cf854185ffceda15306571f791b4da
parent 9e4f0122f5264fdab7b786adcbd37a232f84ea57
Author: Kieran <kieran@harkin.me>
Date: Thu, 30 Nov 2023 23:11:16 +0000
relays: Publish kind 10_002
Closes: https://github.com/damus-io/damus/pull/1783
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
5 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/damus/Models/Contacts.swift b/damus/Models/Contacts.swift
@@ -217,6 +217,20 @@ func add_relay(ev: NostrEvent, keypair: FullKeypair, current_relays: [RelayDescr
return NostrEvent(content: content, keypair: keypair.to_keypair(), kind: 3, tags: ev.tags.strings())
}
+func make_relay_metadata(relays: [RelayDescriptor], keypair: FullKeypair) -> NostrEvent? {
+ let tags = relays.compactMap { r -> [String]? in
+ var tag = ["r", r.url.id]
+ if (r.info.read ?? true) != (r.info.write ?? true) {
+ tag += r.info.read == true ? ["read"] : ["write"]
+ }
+ if ((r.info.read ?? true) || (r.info.write ?? true)) && r.variant == .regular {
+ return tag;
+ }
+ return nil
+ }
+ return NostrEvent(content: "", keypair: keypair.to_keypair(), kind: 10_002, tags: tags)
+}
+
func ensure_relay_info(relays: [RelayDescriptor], content: String) -> [RelayURL: RelayInfo] {
return decode_json_relays(content) ?? make_contact_relays(relays)
}
diff --git a/damus/Views/AddRelayView.swift b/damus/Views/AddRelayView.swift
@@ -113,6 +113,9 @@ struct AddRelayView: View {
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)
+ }
new_relay = ""
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
diff --git a/damus/Views/Relays/RecommendedRelayView.swift b/damus/Views/Relays/RecommendedRelayView.swift
@@ -124,6 +124,10 @@ struct RecommendedRelayView: View {
}
process_contact_event(state: damus, ev: ev_after_add)
damus.postbox.send(ev_after_add)
+
+ if let relay_metadata = make_relay_metadata(relays: damus.pool.our_descriptors, keypair: keypair) {
+ damus.postbox.send(relay_metadata)
+ }
}
}
diff --git a/damus/Views/Relays/RelayDetailView.swift b/damus/Views/Relays/RelayDetailView.swift
@@ -55,6 +55,10 @@ struct RelayDetailView: View {
process_contact_event(state: state, ev: new_ev)
state.postbox.send(new_ev)
+
+ if let relay_metadata = make_relay_metadata(relays: state.pool.our_descriptors, keypair: keypair) {
+ state.postbox.send(relay_metadata)
+ }
dismiss()
}) {
Text("Disconnect From Relay", comment: "Button to disconnect from the relay.")
@@ -78,6 +82,10 @@ struct RelayDetailView: View {
}
process_contact_event(state: state, ev: ev_after_add)
state.postbox.send(ev_after_add)
+
+ if let relay_metadata = make_relay_metadata(relays: state.pool.our_descriptors, keypair: keypair) {
+ state.postbox.send(relay_metadata)
+ }
dismiss()
}) {
Text("Connect To Relay", comment: "Button to connect to the relay.")
diff --git a/damus/Views/Relays/RelayView.swift b/damus/Views/Relays/RelayView.swift
@@ -102,6 +102,10 @@ struct RelayView: View {
process_contact_event(state: state, ev: new_ev)
state.postbox.send(new_ev)
+
+ if let relay_metadata = make_relay_metadata(relays: state.pool.our_descriptors, keypair: keypair) {
+ state.postbox.send(relay_metadata)
+ }
}) {
if showText {
Text(NSLocalizedString("Disconnect", comment: "Button to disconnect from a relay server."))