notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 320dedc8bd5f8c1f294715cea4de420cb65da3a8
parent 41e141d9a9be1faa125a8894f40e2bc0b44eaffa
Author: kernelkind <kernelkind@gmail.com>
Date:   Wed, 25 Jun 2025 16:29:40 -0400

add `RelayDefaults`

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck/src/account/accounts.rs | 32+++++++++-----------------------
Mcrates/notedeck/src/account/relay.rs | 30++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/crates/notedeck/src/account/accounts.rs b/crates/notedeck/src/account/accounts.rs @@ -1,7 +1,7 @@ use tracing::{debug, error, info}; use crate::account::mute::AccountMutedData; -use crate::account::relay::AccountRelayData; +use crate::account::relay::{AccountRelayData, RelayDefaults}; use crate::{AccountStorage, MuteFun, RelaySpec, SingleUnkIdAction, UnknownIds, UserAccount}; use enostr::{ClientMessage, FilledKeypair, Keypair, Pubkey, RelayPool}; use nostrdb::{Ndb, Note, Transaction}; @@ -18,8 +18,7 @@ pub struct Accounts { accounts: Vec<UserAccount>, key_store: Option<AccountStorage>, account_data: BTreeMap<[u8; 32], AccountData>, - forced_relays: BTreeSet<RelaySpec>, - bootstrap_relays: BTreeSet<RelaySpec>, + relay_defaults: RelayDefaults, needs_relay_config: bool, fallback: Option<Pubkey>, } @@ -44,29 +43,15 @@ impl Accounts { }; let account_data = BTreeMap::new(); - let forced_relays: BTreeSet<RelaySpec> = forced_relays - .into_iter() - .map(|u| RelaySpec::new(AccountRelayData::canonicalize_url(&u), false, false)) - .collect(); - let bootstrap_relays = [ - "wss://relay.damus.io", - // "wss://pyramid.fiatjaf.com", // Uncomment if needed - "wss://nos.lol", - "wss://nostr.wine", - "wss://purplepag.es", - ] - .iter() - .map(|&url| url.to_string()) - .map(|u| RelaySpec::new(AccountRelayData::canonicalize_url(&u), false, false)) - .collect(); + + let relay_defaults = RelayDefaults::new(forced_relays); Accounts { currently_selected_account, accounts, key_store, account_data, - forced_relays, - bootstrap_relays, + relay_defaults, needs_relay_config: true, fallback: None, } @@ -424,7 +409,7 @@ impl Accounts { ); // If forced relays are set use them only - let mut desired_relays = self.forced_relays.clone(); + let mut desired_relays = self.relay_defaults.forced_relays.clone(); // Compose the desired relay lists from the selected account if desired_relays.is_empty() { @@ -436,7 +421,7 @@ impl Accounts { // If no relays are specified at this point use the bootstrap list if desired_relays.is_empty() { - desired_relays = self.bootstrap_relays.clone(); + desired_relays = self.relay_defaults.bootstrap_relays.clone(); } debug!("current relays: {:?}", pool.urls()); @@ -575,7 +560,8 @@ impl Accounts { if advertised.is_empty() { // If the selected account has no advertised relays, // initialize with the bootstrapping set. - advertised.extend(self.bootstrap_relays.iter().cloned()); + advertised + .extend(self.relay_defaults.bootstrap_relays.iter().cloned()); } match action { RelayAction::Add => { diff --git a/crates/notedeck/src/account/relay.rs b/crates/notedeck/src/account/relay.rs @@ -149,3 +149,33 @@ impl AccountRelayData { pool.send(&enostr::ClientMessage::event(&note).expect("note client message")); } } + +pub(crate) struct RelayDefaults { + pub forced_relays: BTreeSet<RelaySpec>, + pub bootstrap_relays: BTreeSet<RelaySpec>, +} + +impl RelayDefaults { + pub(crate) fn new(forced_relays: Vec<String>) -> Self { + let forced_relays: BTreeSet<RelaySpec> = forced_relays + .into_iter() + .map(|u| RelaySpec::new(AccountRelayData::canonicalize_url(&u), false, false)) + .collect(); + let bootstrap_relays = [ + "wss://relay.damus.io", + // "wss://pyramid.fiatjaf.com", // Uncomment if needed + "wss://nos.lol", + "wss://nostr.wine", + "wss://purplepag.es", + ] + .iter() + .map(|&url| url.to_string()) + .map(|u| RelaySpec::new(AccountRelayData::canonicalize_url(&u), false, false)) + .collect(); + + Self { + forced_relays, + bootstrap_relays, + } + } +}