From 98cb082fb454c544a15dba08fc56bb468aabbaed Mon Sep 17 00:00:00 2001 From: kernelkind Date: Fri, 16 May 2025 15:50:31 -0400 Subject: [PATCH] hotfix: can login again adds fallback pubkey as account and selects it when there are no accounts closes: https://github.com/damus-io/notedeck/issues/855 Signed-off-by: kernelkind --- crates/notedeck/src/accounts.rs | 26 +++++++++++++++++++++++++- crates/notedeck/src/app.rs | 3 ++- crates/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 index d3c50c2..edd81ac 100644 --- a/crates/notedeck/src/accounts.rs +++ b/crates/notedeck/src/accounts.rs @@ -313,6 +313,7 @@ pub struct Accounts { forced_relays: BTreeSet, bootstrap_relays: BTreeSet, needs_relay_config: bool, + fallback: Option, } 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 index 70920b4..e8087ec 100644 --- 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 index 6ea1cbc..f0e4ea3 100644 --- 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,