Skip to content

Commit 2ecde85

Browse files
committed
prune account code; don't manage pool, deprecate local and forced relays
- local relays are very doable, but not sure if we want them - forced relays want to be implemented in the pool/subman and need more definition
1 parent 5b720d5 commit 2ecde85

File tree

1 file changed

+7
-79
lines changed

1 file changed

+7
-79
lines changed

crates/notedeck/src/accounts.rs

+7-79
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub enum AccountsAction {
3838
pub struct AccountRelayData {
3939
filter: Filter,
4040
subrmtid: Option<RmtId>,
41-
local: BTreeSet<RelaySpec>, // used locally but not advertised
41+
_local: BTreeSet<RelaySpec>, // used locally but not advertised
4242
advertised: Arc<Mutex<BTreeSet<RelaySpec>>>, // advertised via NIP-65
4343
}
4444

@@ -82,7 +82,7 @@ impl AccountRelayData {
8282
AccountRelayData {
8383
filter,
8484
subrmtid: None,
85-
local: BTreeSet::new(),
85+
_local: BTreeSet::new(),
8686
advertised: Arc::new(Mutex::new(relays.into_iter().collect())),
8787
}
8888
}
@@ -343,13 +343,13 @@ pub struct Accounts {
343343
accounts: Vec<UserAccount>,
344344
key_store: KeyStorageType,
345345
account_data: BTreeMap<[u8; 32], AccountData>,
346-
forced_relays: BTreeSet<RelaySpec>,
346+
_forced_relays: BTreeSet<RelaySpec>,
347347
bootstrap_relays: BTreeSet<RelaySpec>,
348348
needs_relay_config: bool,
349349
}
350350

351351
impl Accounts {
352-
pub fn new(key_store: KeyStorageType, forced_relays: Vec<String>) -> Self {
352+
pub fn new(key_store: KeyStorageType, _forced_relays: Vec<String>) -> Self {
353353
let accounts = if let KeyStorageResponse::ReceivedResult(res) = key_store.get_keys() {
354354
res.unwrap_or_default()
355355
} else {
@@ -358,7 +358,7 @@ impl Accounts {
358358

359359
let currently_selected_account = get_selected_index(&accounts, &key_store);
360360
let account_data = BTreeMap::new();
361-
let forced_relays: BTreeSet<RelaySpec> = forced_relays
361+
let _forced_relays: BTreeSet<RelaySpec> = _forced_relays
362362
.into_iter()
363363
.map(|u| RelaySpec::new(AccountRelayData::canonicalize_url(&u), false, false))
364364
.collect();
@@ -379,7 +379,7 @@ impl Accounts {
379379
accounts,
380380
key_store,
381381
account_data,
382-
forced_relays,
382+
_forced_relays,
383383
bootstrap_relays,
384384
needs_relay_config: true,
385385
}
@@ -592,61 +592,6 @@ impl Accounts {
592592
self.account_data.remove(pubkey);
593593
}
594594

595-
fn update_relay_configuration(
596-
&mut self,
597-
pool: &mut RelayPool,
598-
wakeup: impl Fn() + Send + Sync + Clone + 'static,
599-
) {
600-
debug!(
601-
"updating relay configuration for currently selected {:?}",
602-
self.currently_selected_account
603-
.map(|i| hex::encode(self.accounts.get(i).unwrap().pubkey.bytes()))
604-
);
605-
606-
// If forced relays are set use them only
607-
let mut desired_relays = self.forced_relays.clone();
608-
609-
// Compose the desired relay lists from the selected account
610-
if desired_relays.is_empty() {
611-
if let Some(data) = self.get_selected_account_data() {
612-
desired_relays.extend(data.relay.local.iter().cloned());
613-
desired_relays.extend(data.relay.advertised.lock().unwrap().iter().cloned());
614-
}
615-
}
616-
617-
// If no relays are specified at this point use the bootstrap list
618-
if desired_relays.is_empty() {
619-
desired_relays = self.bootstrap_relays.clone();
620-
}
621-
622-
debug!("current relays: {:?}", pool.urls());
623-
debug!("desired relays: {:?}", desired_relays);
624-
625-
let pool_specs = pool
626-
.urls()
627-
.iter()
628-
.map(|url| RelaySpec::new(url.clone(), false, false))
629-
.collect();
630-
let add: BTreeSet<RelaySpec> = desired_relays.difference(&pool_specs).cloned().collect();
631-
let mut sub: BTreeSet<RelaySpec> =
632-
pool_specs.difference(&desired_relays).cloned().collect();
633-
if !add.is_empty() {
634-
debug!("configuring added relays: {:?}", add);
635-
let _ = pool.add_urls(add.iter().map(|r| r.url.clone()).collect(), wakeup);
636-
}
637-
if !sub.is_empty() {
638-
// certain relays are persistent like the multicast relay,
639-
// although we should probably have a way to explicitly
640-
// disable it
641-
sub.remove(&RelaySpec::new("multicast", false, false));
642-
643-
debug!("removing unwanted relays: {:?}", sub);
644-
pool.remove_urls(&sub.iter().map(|r| r.url.clone()).collect());
645-
}
646-
647-
debug!("current relays: {:?}", pool.urls());
648-
}
649-
650595
fn get_combined_relays(
651596
&self,
652597
data_option: Option<&AccountData>,
@@ -688,18 +633,10 @@ impl Accounts {
688633
self.get_combined_relays(self.get_selected_account_data(), |_| true)
689634
}
690635

691-
pub fn update(&mut self, subman: &mut SubMan, ctx: &egui::Context) {
636+
pub fn update(&mut self, subman: &mut SubMan, _ctx: &egui::Context) {
692637
// IMPORTANT - This function is called in the UI update loop,
693638
// make sure it is fast when idle
694639

695-
// On the initial update the relays need config even if nothing changes below
696-
let mut need_reconfig = self.needs_relay_config;
697-
698-
let ctx2 = ctx.clone();
699-
let wakeup = move || {
700-
ctx2.request_repaint();
701-
};
702-
703640
// Do we need to deactivate any existing account subs?
704641
for (ndx, account) in self.accounts.iter().enumerate() {
705642
if Some(ndx) != self.currently_selected_account {
@@ -718,23 +655,14 @@ impl Accounts {
718655
}
719656

720657
let ndb = subman.ndb().clone();
721-
let pool = subman.pool();
722658

723659
// Were any accounts added or removed?
724660
let (added, removed) = self.delta_accounts();
725661
for pk in added {
726662
self.handle_added_account(&ndb, &pk);
727-
need_reconfig = true;
728663
}
729664
for pk in removed {
730665
self.handle_removed_account(&pk);
731-
need_reconfig = true;
732-
}
733-
734-
// If needed, update the relay configuration
735-
if need_reconfig {
736-
self.update_relay_configuration(pool, wakeup);
737-
self.needs_relay_config = false;
738666
}
739667

740668
// Do we need to activate account subs?

0 commit comments

Comments
 (0)