diff --git a/crates/notedeck/src/accounts.rs b/crates/notedeck/src/accounts.rs index 79c638fb..6e7acc40 100644 --- a/crates/notedeck/src/accounts.rs +++ b/crates/notedeck/src/accounts.rs @@ -38,7 +38,7 @@ pub enum AccountsAction { pub struct AccountRelayData { filter: Filter, subrmtid: Option, - local: BTreeSet, // used locally but not advertised + _local: BTreeSet, // used locally but not advertised advertised: Arc>>, // advertised via NIP-65 } @@ -82,7 +82,7 @@ impl AccountRelayData { AccountRelayData { filter, subrmtid: None, - local: BTreeSet::new(), + _local: BTreeSet::new(), advertised: Arc::new(Mutex::new(relays.into_iter().collect())), } } @@ -343,13 +343,13 @@ pub struct Accounts { accounts: Vec, key_store: KeyStorageType, account_data: BTreeMap<[u8; 32], AccountData>, - forced_relays: BTreeSet, + _forced_relays: BTreeSet, bootstrap_relays: BTreeSet, needs_relay_config: bool, } impl Accounts { - pub fn new(key_store: KeyStorageType, forced_relays: Vec) -> Self { + pub fn new(key_store: KeyStorageType, _forced_relays: Vec) -> Self { let accounts = if let KeyStorageResponse::ReceivedResult(res) = key_store.get_keys() { res.unwrap_or_default() } else { @@ -358,7 +358,7 @@ impl Accounts { let currently_selected_account = get_selected_index(&accounts, &key_store); let account_data = BTreeMap::new(); - let forced_relays: BTreeSet = forced_relays + let _forced_relays: BTreeSet = _forced_relays .into_iter() .map(|u| RelaySpec::new(AccountRelayData::canonicalize_url(&u), false, false)) .collect(); @@ -379,7 +379,7 @@ impl Accounts { accounts, key_store, account_data, - forced_relays, + _forced_relays, bootstrap_relays, needs_relay_config: true, } @@ -592,61 +592,6 @@ impl Accounts { self.account_data.remove(pubkey); } - fn update_relay_configuration( - &mut self, - pool: &mut RelayPool, - wakeup: impl Fn() + Send + Sync + Clone + 'static, - ) { - debug!( - "updating relay configuration for currently selected {:?}", - self.currently_selected_account - .map(|i| hex::encode(self.accounts.get(i).unwrap().pubkey.bytes())) - ); - - // If forced relays are set use them only - let mut desired_relays = self.forced_relays.clone(); - - // Compose the desired relay lists from the selected account - if desired_relays.is_empty() { - if let Some(data) = self.get_selected_account_data() { - desired_relays.extend(data.relay.local.iter().cloned()); - desired_relays.extend(data.relay.advertised.lock().unwrap().iter().cloned()); - } - } - - // If no relays are specified at this point use the bootstrap list - if desired_relays.is_empty() { - desired_relays = self.bootstrap_relays.clone(); - } - - debug!("current relays: {:?}", pool.urls()); - debug!("desired relays: {:?}", desired_relays); - - let pool_specs = pool - .urls() - .iter() - .map(|url| RelaySpec::new(url.clone(), false, false)) - .collect(); - let add: BTreeSet = desired_relays.difference(&pool_specs).cloned().collect(); - let mut sub: BTreeSet = - pool_specs.difference(&desired_relays).cloned().collect(); - if !add.is_empty() { - debug!("configuring added relays: {:?}", add); - let _ = pool.add_urls(add.iter().map(|r| r.url.clone()).collect(), wakeup); - } - if !sub.is_empty() { - // certain relays are persistent like the multicast relay, - // although we should probably have a way to explicitly - // disable it - sub.remove(&RelaySpec::new("multicast", false, false)); - - debug!("removing unwanted relays: {:?}", sub); - pool.remove_urls(&sub.iter().map(|r| r.url.clone()).collect()); - } - - debug!("current relays: {:?}", pool.urls()); - } - fn get_combined_relays( &self, data_option: Option<&AccountData>, @@ -688,18 +633,10 @@ impl Accounts { self.get_combined_relays(self.get_selected_account_data(), |_| true) } - pub fn update(&mut self, subman: &mut SubMan, ctx: &egui::Context) { + pub fn update(&mut self, subman: &mut SubMan, _ctx: &egui::Context) { // IMPORTANT - This function is called in the UI update loop, // make sure it is fast when idle - // On the initial update the relays need config even if nothing changes below - let mut need_reconfig = self.needs_relay_config; - - let ctx2 = ctx.clone(); - let wakeup = move || { - ctx2.request_repaint(); - }; - // Do we need to deactivate any existing account subs? for (ndx, account) in self.accounts.iter().enumerate() { if Some(ndx) != self.currently_selected_account { @@ -718,23 +655,14 @@ impl Accounts { } let ndb = subman.ndb().clone(); - let pool = subman.pool(); // Were any accounts added or removed? let (added, removed) = self.delta_accounts(); for pk in added { self.handle_added_account(&ndb, &pk); - need_reconfig = true; } for pk in removed { self.handle_removed_account(&pk); - need_reconfig = true; - } - - // If needed, update the relay configuration - if need_reconfig { - self.update_relay_configuration(pool, wakeup); - self.needs_relay_config = false; } // Do we need to activate account subs?