mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 17:14:21 +01:00
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 <kernelkind@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user