publish NIP-65 relay lists

This commit is contained in:
Ken Sedgwick
2025-01-22 15:16:08 -08:00
parent 3278d3ba16
commit 94a1d78114
2 changed files with 24 additions and 4 deletions

View File

@@ -5,7 +5,7 @@ use crate::{
UserAccount, UserAccount,
}; };
use enostr::{ClientMessage, FilledKeypair, Keypair, RelayPool}; use enostr::{ClientMessage, FilledKeypair, Keypair, RelayPool};
use nostrdb::{Filter, Ndb, Note, NoteKey, Subscription, Transaction}; use nostrdb::{Filter, Ndb, Note, NoteBuilder, NoteKey, Subscription, Transaction};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use url::Url; use url::Url;
@@ -144,6 +144,20 @@ impl AccountRelayData {
} }
relays relays
} }
pub fn publish_nip65_relays(&self, seckey: &[u8; 32], pool: &mut RelayPool) {
let mut builder = NoteBuilder::new().kind(10002).content("");
for rs in &self.advertised {
builder = builder.start_tag().tag_str("r").tag_str(&rs.url);
if rs.has_read_marker {
builder = builder.tag_str("read");
} else if rs.has_write_marker {
builder = builder.tag_str("write");
}
}
let note = builder.sign(seckey).build().expect("note build");
pool.send(&enostr::ClientMessage::event(note).expect("note client message"));
}
} }
pub struct AccountMutedData { pub struct AccountMutedData {
@@ -607,7 +621,7 @@ impl Accounts {
None None
} }
pub fn add_advertised_relay(&mut self, relay_to_add: &str) { pub fn add_advertised_relay(&mut self, relay_to_add: &str, pool: &mut RelayPool) {
let relay_to_add = AccountRelayData::canonicalize_url(relay_to_add); let relay_to_add = AccountRelayData::canonicalize_url(relay_to_add);
info!("add advertised relay \"{}\"", relay_to_add); info!("add advertised relay \"{}\"", relay_to_add);
match self.currently_selected_account { match self.currently_selected_account {
@@ -627,7 +641,12 @@ impl Accounts {
} }
advertised.insert(RelaySpec::new(relay_to_add, false, false)); advertised.insert(RelaySpec::new(relay_to_add, false, false));
self.needs_relay_config = true; self.needs_relay_config = true;
// FIXME - need to publish the advertised set // If we have the secret key publish the nip-65 relay list
if let Some(secretkey) = &keypair.secret_key {
account_data
.relay
.publish_nip65_relays(&secretkey.to_secret_bytes(), pool);
}
} }
} }
} }

View File

@@ -42,7 +42,8 @@ impl View for RelayView<'_> {
} }
ui.add_space(8.0); ui.add_space(8.0);
if let Some(relay_to_add) = self.show_add_relay_ui(ui) { if let Some(relay_to_add) = self.show_add_relay_ui(ui) {
self.accounts.add_advertised_relay(&relay_to_add); self.accounts
.add_advertised_relay(&relay_to_add, self.manager.pool);
} }
}); });
} }