notedeck

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

commit 163abe891acb5a65ae0c2c8c8a656baa93abdb54
parent 5598cc8ba0ed79d8642b31b21b90a143c9b2bac0
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 19 May 2025 15:25:56 -0700

Merge remote-tracking branch 'pr/862'

Diffstat:
Mcrates/notedeck/src/accounts.rs | 26+++++++++++++++++++++++++-
Mcrates/notedeck/src/app.rs | 3++-
Mcrates/notedeck_columns/src/app.rs | 2++
3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/crates/notedeck/src/accounts.rs b/crates/notedeck/src/accounts.rs @@ -313,6 +313,7 @@ pub struct Accounts { forced_relays: BTreeSet<RelaySpec>, bootstrap_relays: BTreeSet<RelaySpec>, needs_relay_config: bool, + fallback: Option<Pubkey>, } impl Accounts { @@ -359,6 +360,7 @@ impl Accounts { forced_relays, bootstrap_relays, needs_relay_config: true, + fallback: None, } } @@ -386,6 +388,10 @@ impl Accounts { .find(|acc| acc.key.pubkey.bytes() == pk) } + pub fn with_fallback(&mut self, fallback: Pubkey) { + self.fallback = Some(fallback); + } + pub fn remove_account(&mut self, index: usize) { if let Some(account) = self.accounts.get(index) { if let Some(key_store) = &self.key_store { @@ -659,6 +665,14 @@ impl Accounts { self.account_data.remove(pubkey); } + fn handle_no_accounts(&mut self, unknown_ids: &mut UnknownIds, ndb: &Ndb, txn: &Transaction) { + if let Some(fallback) = self.fallback { + self.add_account(Keypair::new(fallback, None)) + .process_action(unknown_ids, ndb, txn); + self.select_account(self.num_accounts() - 1); + } + } + fn poll_for_updates(&mut self, ndb: &Ndb) -> bool { let mut changed = false; for (pubkey, data) in &mut self.account_data { @@ -745,7 +759,13 @@ impl Accounts { debug!("current relays: {:?}", pool.urls()); } - pub fn update(&mut self, ndb: &mut Ndb, pool: &mut RelayPool, ctx: &egui::Context) { + pub fn update( + &mut self, + ndb: &mut Ndb, + pool: &mut RelayPool, + ctx: &egui::Context, + unknown_ids: &mut UnknownIds, + ) { // IMPORTANT - This function is called in the UI update loop, // make sure it is fast when idle @@ -785,6 +805,10 @@ impl Accounts { need_reconfig = true; } + if self.accounts.is_empty() { + let txn = Transaction::new(ndb).unwrap(); + self.handle_no_accounts(unknown_ids, ndb, &txn); + } // Did any accounts receive updates (ie NIP-65 relay lists) need_reconfig = self.poll_for_updates(ndb) || need_reconfig; diff --git a/crates/notedeck/src/app.rs b/crates/notedeck/src/app.rs @@ -93,7 +93,8 @@ impl eframe::App for Notedeck { .on_new_frame(ctx.input(|i| i.time), frame.info().cpu_usage); // handle account updates - self.accounts.update(&mut self.ndb, &mut self.pool, ctx); + self.accounts + .update(&mut self.ndb, &mut self.pool, ctx, &mut self.unknown_ids); self.zaps .process(&mut self.accounts, &mut self.global_wallet, &self.ndb); diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs @@ -433,6 +433,8 @@ impl Damus { let jobs = JobsCache::default(); + ctx.accounts.with_fallback(FALLBACK_PUBKEY()); + Self { subscriptions: Subscriptions::default(), since_optimize: parsed_args.since_optimize,