notedeck

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

commit 8e92a97a57a66f50bed16a6dc47d9bf14eab1140
parent 9cacb6bb6930281b15c8855e99ec829b0122cbe7
Author: kernelkind <kernelkind@gmail.com>
Date:   Wed, 25 Jun 2025 22:09:55 -0400

make selected accounts non optional

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck/src/account/accounts.rs | 29+++++++++++++----------------
Mcrates/notedeck/src/zaps/cache.rs | 6+-----
Mcrates/notedeck_chrome/src/chrome.rs | 49+++++++++++++++++++------------------------------
Mcrates/notedeck_columns/src/app.rs | 19+++++--------------
Mcrates/notedeck_columns/src/decks.rs | 2+-
Mcrates/notedeck_columns/src/nav.rs | 29++++++++++++++---------------
Mcrates/notedeck_columns/src/timeline/route.rs | 6+++---
Mcrates/notedeck_columns/src/ui/add_column.rs | 116+++++++++++++++++++++++++++++++++----------------------------------------------
Mcrates/notedeck_columns/src/ui/profile/mod.rs | 5+----
Mcrates/notedeck_columns/src/ui/search/mod.rs | 4++--
Mcrates/notedeck_columns/src/ui/side_panel.rs | 16+++++-----------
Mcrates/notedeck_columns/src/ui/thread.rs | 11+++++------
Mcrates/notedeck_columns/src/ui/timeline.rs | 20++++++++++----------
Mcrates/notedeck_columns/src/ui/wallet.rs | 12+++++-------
Mcrates/notedeck_dave/src/lib.rs | 6+-----
Mcrates/notedeck_dave/src/ui/dave.rs | 4+++-
16 files changed, 137 insertions(+), 197 deletions(-)

diff --git a/crates/notedeck/src/account/accounts.rs b/crates/notedeck/src/account/accounts.rs @@ -195,9 +195,7 @@ impl Accounts { update(cur_account); } - let Some(cur_acc) = self.get_selected_account() else { - return false; - }; + let cur_acc = self.get_selected_account(); let Some(key_store) = &self.key_store else { return false; @@ -221,31 +219,30 @@ impl Accounts { pub fn selected_or_first_nsec(&self) -> Option<FilledKeypair<'_>> { self.get_selected_account() - .and_then(|kp| kp.key.to_full()) + .key + .to_full() .or_else(|| self.accounts.iter().find_map(|a| a.key.to_full())) } /// Get the selected account's pubkey as bytes. Common operation so /// we make it a helper here. - pub fn selected_account_pubkey_bytes(&self) -> Option<&[u8; 32]> { - self.get_selected_account().map(|kp| kp.key.pubkey.bytes()) + pub fn selected_account_pubkey_bytes(&self) -> &[u8; 32] { + self.get_selected_account().key.pubkey.bytes() } - pub fn selected_account_pubkey(&self) -> Option<&Pubkey> { - self.get_selected_account().map(|acc| &acc.key.pubkey) + pub fn selected_account_pubkey(&self) -> &Pubkey { + &self.get_selected_account().key.pubkey } - pub fn get_selected_account(&self) -> Option<&UserAccount> { + pub fn get_selected_account(&self) -> &UserAccount { self.currently_selected_account - .map(|i| self.get_account(i))? + .and_then(|i| self.get_account(i)) + // NOTE: yeah, this is incorrect but we just need to seperate out the changes in smaller commits + .unwrap() } pub fn selected_account_has_wallet(&self) -> bool { - if let Some(acc) = self.get_selected_account() { - return acc.wallet.is_some(); - } - - false + self.get_selected_account().wallet.is_some() } pub fn get_selected_account_mut(&mut self) -> Option<&mut UserAccount> { @@ -265,7 +262,7 @@ impl Accounts { } pub fn get_selected_account_data(&mut self) -> Option<&mut AccountData> { - let account_pubkey = *self.selected_account_pubkey_bytes()?; + let account_pubkey = *self.selected_account_pubkey_bytes(); self.account_data.get_mut(&account_pubkey) } diff --git a/crates/notedeck/src/zaps/cache.rs b/crates/notedeck/src/zaps/cache.rs @@ -81,11 +81,7 @@ fn process_new_zap_event( txn: &Transaction, sender_relays: Vec<String>, ) -> NextState { - let Some(full_kp) = accounts - .get_selected_account() - .or_else(|| accounts.find_account(zap_ctx.key.sender.bytes())) - .and_then(|u| u.key.to_full()) - else { + let Some(full_kp) = accounts.get_selected_account().key.to_full() else { return NextState::Event(EventResponse { id: zap_ctx.id, event: Err(ZappingError::InvalidAccount), diff --git a/crates/notedeck_chrome/src/chrome.rs b/crates/notedeck_chrome/src/chrome.rs @@ -5,10 +5,7 @@ use crate::app::NotedeckApp; use egui::{vec2, Button, Label, Layout, Rect, RichText, ThemePreference, Widget}; use egui_extras::{Size, StripBuilder}; use nostrdb::{ProfileRecord, Transaction}; -use notedeck::{ - profile::get_profile_url, App, AppAction, AppContext, NotedeckTextStyle, UserAccount, - WalletType, -}; +use notedeck::{App, AppAction, AppContext, NotedeckTextStyle, UserAccount, WalletType}; use notedeck_columns::{timeline::kind::ListKind, timeline::TimelineKind, Damus}; use notedeck_dave::{Dave, DaveAvatar}; @@ -95,27 +92,23 @@ impl ChromePanelAction { ToolbarAction::Dave => chrome.switch_to_dave(), ToolbarAction::Home => { - if let Some(pubkey) = ctx - .accounts - .get_selected_account() - .map(|acc| acc.key.pubkey) - { - Self::columns_switch( - ctx, - chrome, - &TimelineKind::List(ListKind::Contact(pubkey)), - ); - } + Self::columns_switch( + ctx, + chrome, + &TimelineKind::List(ListKind::Contact( + ctx.accounts.get_selected_account().key.pubkey, + )), + ); } ToolbarAction::Notifications => { - if let Some(pubkey) = ctx - .accounts - .get_selected_account() - .map(|acc| acc.key.pubkey) - { - Self::columns_switch(ctx, chrome, &TimelineKind::Notifications(pubkey)); - } + Self::columns_switch( + ctx, + chrome, + &TimelineKind::Notifications( + ctx.accounts.get_selected_account().key.pubkey, + ), + ); } }, @@ -559,16 +552,12 @@ pub fn get_profile_url_owned(profile: Option<ProfileRecord<'_>>) -> &str { pub fn get_account_url<'a>( txn: &'a nostrdb::Transaction, ndb: &nostrdb::Ndb, - account: Option<&UserAccount>, + account: &UserAccount, ) -> &'a str { - if let Some(selected_account) = account { - if let Ok(profile) = ndb.get_profile_by_pubkey(txn, selected_account.key.pubkey.bytes()) { - get_profile_url_owned(Some(profile)) - } else { - get_profile_url_owned(None) - } + if let Ok(profile) = ndb.get_profile_by_pubkey(txn, account.key.pubkey.bytes()) { + get_profile_url_owned(Some(profile)) } else { - get_profile_url(None) + get_profile_url_owned(None) } } diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs @@ -386,7 +386,7 @@ impl Damus { // arg parsing let (parsed_args, unrecognized_args) = - ColumnsArgs::parse(args, ctx.accounts.selected_account_pubkey()); + ColumnsArgs::parse(args, Some(ctx.accounts.selected_account_pubkey())); let account = ctx.accounts.selected_account_pubkey_bytes(); @@ -747,9 +747,7 @@ pub fn get_active_columns<'a>(accounts: &Accounts, decks_cache: &'a DecksCache) } pub fn get_decks<'a>(accounts: &Accounts, decks_cache: &'a DecksCache) -> &'a Decks { - let key = accounts - .selected_account_pubkey() - .unwrap_or_else(|| decks_cache.get_fallback_pubkey()); + let key = accounts.selected_account_pubkey(); decks_cache.decks(key) } @@ -763,10 +761,7 @@ pub fn get_active_columns_mut<'a>( } pub fn get_decks_mut<'a>(accounts: &Accounts, decks_cache: &'a mut DecksCache) -> &'a mut Decks { - match accounts.selected_account_pubkey() { - Some(acc) => decks_cache.decks_mut(acc), - None => decks_cache.fallback_mut(), - } + decks_cache.decks_mut(accounts.selected_account_pubkey()) } pub fn set_demo( @@ -782,7 +777,7 @@ pub fn set_demo( accounts.select_account(accounts.num_accounts() - 1); } -fn columns_to_decks_cache(cols: Columns, key: Option<&[u8; 32]>) -> DecksCache { +fn columns_to_decks_cache(cols: Columns, key: &[u8; 32]) -> DecksCache { let mut account_to_decks: HashMap<Pubkey, Decks> = Default::default(); let decks = Decks::new(crate::decks::Deck::new_with_columns( crate::decks::Deck::default().icon, @@ -790,11 +785,7 @@ fn columns_to_decks_cache(cols: Columns, key: Option<&[u8; 32]>) -> DecksCache { cols, )); - let account = if let Some(key) = key { - Pubkey::new(*key) - } else { - FALLBACK_PUBKEY() - }; + let account = Pubkey::new(*key); account_to_decks.insert(account, decks); DecksCache::new(account_to_decks) } diff --git a/crates/notedeck_columns/src/decks.rs b/crates/notedeck_columns/src/decks.rs @@ -39,7 +39,7 @@ impl DecksCache { /// Gets the active columns pub fn active_columns_mut(&mut self, accounts: &notedeck::Accounts) -> Option<&mut Columns> { - let account = accounts.get_selected_account()?; + let account = accounts.get_selected_account(); self.decks_mut(&account.key.pubkey) .active_deck_mut() diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs @@ -544,7 +544,7 @@ fn render_nav_body( response.action.map(Into::into) } Route::ComposeNote => { - let kp = ctx.accounts.get_selected_account()?.key.to_full()?; + let kp = ctx.accounts.get_selected_account().key.to_full()?; let draft = app.drafts.compose_mut(); let txn = Transaction::new(ctx.ndb).expect("txn"); @@ -594,7 +594,7 @@ fn render_nav_body( app.note_options, search_buffer, &mut note_context, - &ctx.accounts.get_selected_account().map(|a| (&a.key).into()), + &(&ctx.accounts.get_selected_account().key).into(), &mut app.jobs, ) .show(ui, ctx.clipboard) @@ -605,19 +605,18 @@ fn render_nav_body( let new_deck_state = app.view_state.id_to_deck_state.entry(id).or_default(); let mut resp = None; if let Some(config_resp) = ConfigureDeckView::new(new_deck_state).ui(ui) { - if let Some(cur_acc) = ctx.accounts.selected_account_pubkey() { - app.decks_cache - .add_deck(*cur_acc, Deck::new(config_resp.icon, config_resp.name)); - - // set new deck as active - let cur_index = get_decks_mut(ctx.accounts, &mut app.decks_cache) - .decks() - .len() - - 1; - resp = Some(RenderNavAction::SwitchingAction(SwitchingAction::Decks( - DecksAction::Switch(cur_index), - ))); - } + let cur_acc = ctx.accounts.selected_account_pubkey(); + app.decks_cache + .add_deck(*cur_acc, Deck::new(config_resp.icon, config_resp.name)); + + // set new deck as active + let cur_index = get_decks_mut(ctx.accounts, &mut app.decks_cache) + .decks() + .len() + - 1; + resp = Some(RenderNavAction::SwitchingAction(SwitchingAction::Decks( + DecksAction::Switch(cur_index), + ))); new_deck_state.clear(); get_active_columns_mut(ctx.accounts, &mut app.decks_cache) diff --git a/crates/notedeck_columns/src/timeline/route.rs b/crates/notedeck_columns/src/timeline/route.rs @@ -35,7 +35,7 @@ pub fn render_timeline_route( &accounts.mutefun(), note_context, note_options, - &accounts.get_selected_account().map(|a| (&a.key).into()), + &(&accounts.get_selected_account().key).into(), jobs, ) .ui(ui); @@ -64,7 +64,7 @@ pub fn render_timeline_route( &accounts.mutefun(), note_context, note_options, - &accounts.get_selected_account().map(|a| (&a.key).into()), + &(&accounts.get_selected_account().key).into(), jobs, ) .ui(ui); @@ -96,7 +96,7 @@ pub fn render_thread_route( note_options, &accounts.mutefun(), note_context, - &accounts.get_selected_account().map(|a| (&a.key).into()), + &(&accounts.get_selected_account().key).into(), jobs, ) .id_source(col) diff --git a/crates/notedeck_columns/src/ui/add_column.rs b/crates/notedeck_columns/src/ui/add_column.rs @@ -165,7 +165,7 @@ pub struct AddColumnView<'a> { key_state_map: &'a mut HashMap<Id, AcquireKeyState>, ndb: &'a Ndb, img_cache: &'a mut Images, - cur_account: Option<&'a UserAccount>, + cur_account: &'a UserAccount, } impl<'a> AddColumnView<'a> { @@ -173,7 +173,7 @@ impl<'a> AddColumnView<'a> { key_state_map: &'a mut HashMap<Id, AcquireKeyState>, ndb: &'a Ndb, img_cache: &'a mut Images, - cur_account: Option<&'a UserAccount>, + cur_account: &'a UserAccount, ) -> Self { Self { key_state_map, @@ -188,7 +188,7 @@ impl<'a> AddColumnView<'a> { for column_option_data in self.get_base_options() { let option = column_option_data.option.clone(); if self.column_option_ui(ui, column_option_data).clicked() { - selected_option = self.cur_account.map(|acct| option.take_as_response(acct)) + selected_option = Some(option.take_as_response(self.cur_account)); } ui.add(Separator::default().spacing(0.0)); @@ -202,7 +202,7 @@ impl<'a> AddColumnView<'a> { for column_option_data in self.get_notifications_options() { let option = column_option_data.option.clone(); if self.column_option_ui(ui, column_option_data).clicked() { - selected_option = self.cur_account.map(|acct| option.take_as_response(acct)); + selected_option = Some(option.take_as_response(self.cur_account)); } ui.add(Separator::default().spacing(0.0)); @@ -233,11 +233,9 @@ impl<'a> AddColumnView<'a> { }; let option = algo_option.option.clone(); - if self.column_option_ui(ui, algo_option).clicked() { - self.cur_account.map(|acct| option.take_as_response(acct)) - } else { - None - } + self.column_option_ui(ui, algo_option) + .clicked() + .then(|| option.take_as_response(self.cur_account)) } fn algo_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> { @@ -249,11 +247,9 @@ impl<'a> AddColumnView<'a> { }; let option = algo_option.option.clone(); - if self.column_option_ui(ui, algo_option).clicked() { - self.cur_account.map(|acct| option.take_as_response(acct)) - } else { - None - } + self.column_option_ui(ui, algo_option) + .clicked() + .then(|| option.take_as_response(self.cur_account)) } fn individual_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> { @@ -261,7 +257,7 @@ impl<'a> AddColumnView<'a> { for column_option_data in self.get_individual_options() { let option = column_option_data.option.clone(); if self.column_option_ui(ui, column_option_data).clicked() { - selected_option = self.cur_account.map(|acct| option.take_as_response(acct)); + selected_option = Some(option.take_as_response(self.cur_account)); } ui.add(Separator::default().spacing(0.0)); @@ -327,12 +323,9 @@ impl<'a> AddColumnView<'a> { } } - if ui.add(add_column_button()).clicked() { - self.cur_account - .map(|acc| to_option(keypair.pubkey).take_as_response(acc)) - } else { - None - } + ui.add(add_column_button()) + .clicked() + .then(|| to_option(keypair.pubkey).take_as_response(self.cur_account)) } else { None }; @@ -453,20 +446,18 @@ impl<'a> AddColumnView<'a> { option: AddColumnOption::Universe, }); - if let Some(acc) = self.cur_account { - let source = if acc.key.secret_key.is_some() { - PubkeySource::DeckAuthor - } else { - PubkeySource::Explicit(acc.key.pubkey) - }; + let source = if self.cur_account.key.secret_key.is_some() { + PubkeySource::DeckAuthor + } else { + PubkeySource::Explicit(self.cur_account.key.pubkey) + }; - vec.push(ColumnOptionData { - title: "Contacts", - description: "See notes from your contacts", - icon: app_images::home_image(), - option: AddColumnOption::Contacts(source), - }); - } + vec.push(ColumnOptionData { + title: "Contacts", + description: "See notes from your contacts", + icon: app_images::home_image(), + option: AddColumnOption::Contacts(source), + }); vec.push(ColumnOptionData { title: "Notifications", description: "Stay up to date with notifications and mentions", @@ -498,20 +489,18 @@ impl<'a> AddColumnView<'a> { fn get_notifications_options(&self) -> Vec<ColumnOptionData> { let mut vec = Vec::new(); - if let Some(acc) = self.cur_account { - let source = if acc.key.secret_key.is_some() { - PubkeySource::DeckAuthor - } else { - PubkeySource::Explicit(acc.key.pubkey) - }; + let source = if self.cur_account.key.secret_key.is_some() { + PubkeySource::DeckAuthor + } else { + PubkeySource::Explicit(self.cur_account.key.pubkey) + }; - vec.push(ColumnOptionData { - title: "Your Notifications", - description: "Stay up to date with your notifications and mentions", - icon: app_images::notifications_image(), - option: AddColumnOption::Notification(source), - }); - } + vec.push(ColumnOptionData { + title: "Your Notifications", + description: "Stay up to date with your notifications and mentions", + icon: app_images::notifications_image(), + option: AddColumnOption::Notification(source), + }); vec.push(ColumnOptionData { title: "Someone else's Notifications", @@ -526,20 +515,18 @@ impl<'a> AddColumnView<'a> { fn get_individual_options(&self) -> Vec<ColumnOptionData> { let mut vec = Vec::new(); - if let Some(acc) = self.cur_account { - let source = if acc.key.secret_key.is_some() { - PubkeySource::DeckAuthor - } else { - PubkeySource::Explicit(acc.key.pubkey) - }; + let source = if self.cur_account.key.secret_key.is_some() { + PubkeySource::DeckAuthor + } else { + PubkeySource::Explicit(self.cur_account.key.pubkey) + }; - vec.push(ColumnOptionData { - title: "Your Notes", - description: "Keep track of your notes & replies", - icon: app_images::profile_image(), - option: AddColumnOption::Individual(source), - }); - } + vec.push(ColumnOptionData { + title: "Your Notes", + description: "Keep track of your notes & replies", + icon: app_images::profile_image(), + option: AddColumnOption::Individual(source), + }); vec.push(ColumnOptionData { title: "Someone else's Notes", @@ -605,13 +592,8 @@ pub fn render_add_column_routes( AddColumnRoute::Base => add_column_view.ui(ui), AddColumnRoute::Algo(r) => match r { AddAlgoRoute::Base => add_column_view.algo_ui(ui), - AddAlgoRoute::LastPerPubkey => { - if let Some(deck_author) = ctx.accounts.get_selected_account() { - add_column_view.algo_last_per_pk_ui(ui, deck_author.key.pubkey) - } else { - None - } - } + AddAlgoRoute::LastPerPubkey => add_column_view + .algo_last_per_pk_ui(ui, ctx.accounts.get_selected_account().key.pubkey), }, AddColumnRoute::UndecidedNotification => add_column_view.notifications_ui(ui), AddColumnRoute::ExternalNotification => add_column_view.external_notification_ui(ui), diff --git a/crates/notedeck_columns/src/ui/profile/mod.rs b/crates/notedeck_columns/src/ui/profile/mod.rs @@ -115,10 +115,7 @@ impl<'a, 'd> ProfileView<'a, 'd> { &txn, self.is_muted, self.note_context, - &self - .accounts - .get_selected_account() - .map(|a| (&a.key).into()), + &(&self.accounts.get_selected_account().key).into(), self.jobs, ) .show(ui) diff --git a/crates/notedeck_columns/src/ui/search/mod.rs b/crates/notedeck_columns/src/ui/search/mod.rs @@ -27,7 +27,7 @@ pub struct SearchView<'a, 'd> { txn: &'a Transaction, is_muted: &'a MuteFun, note_context: &'a mut NoteContext<'d>, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, } @@ -38,7 +38,7 @@ impl<'a, 'd> SearchView<'a, 'd> { note_options: NoteOptions, query: &'a mut SearchQueryState, note_context: &'a mut NoteContext<'d>, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, ) -> Self { Self { diff --git a/crates/notedeck_columns/src/ui/side_panel.rs b/crates/notedeck_columns/src/ui/side_panel.rs @@ -21,7 +21,7 @@ pub static SIDE_PANEL_WIDTH: f32 = 68.0; static ICON_WIDTH: f32 = 40.0; pub struct DesktopSidePanel<'a> { - selected_account: Option<&'a UserAccount>, + selected_account: &'a UserAccount, decks_cache: &'a DecksCache, } @@ -55,7 +55,7 @@ impl SidePanelResponse { } impl<'a> DesktopSidePanel<'a> { - pub fn new(selected_account: Option<&'a UserAccount>, decks_cache: &'a DecksCache) -> Self { + pub fn new(selected_account: &'a UserAccount, decks_cache: &'a DecksCache) -> Self { Self { selected_account, decks_cache, @@ -92,9 +92,7 @@ impl<'a> DesktopSidePanel<'a> { // ui.add_space(24.0); //} - let is_interactive = self - .selected_account - .is_some_and(|s| s.key.secret_key.is_some()); + let is_interactive = self.selected_account.key.secret_key.is_some(); let compose_resp = ui.add(crate::ui::post::compose_note_button( is_interactive, dark_mode, @@ -388,14 +386,10 @@ fn add_deck_button() -> impl Widget { fn show_decks<'a>( ui: &mut egui::Ui, decks_cache: &'a DecksCache, - selected_account: Option<&'a UserAccount>, + selected_account: &'a UserAccount, ) -> InnerResponse<Option<usize>> { let show_decks_id = ui.id().with("show-decks"); - let account_id = if let Some(acc) = selected_account { - acc.key.pubkey - } else { - *decks_cache.get_fallback_pubkey() - }; + let account_id = selected_account.key.pubkey; let (cur_decks, account_id) = ( decks_cache.decks(&account_id), show_decks_id.with(account_id), diff --git a/crates/notedeck_columns/src/ui/thread.rs b/crates/notedeck_columns/src/ui/thread.rs @@ -18,7 +18,7 @@ pub struct ThreadView<'a, 'd> { id_source: egui::Id, is_muted: &'a MuteFun, note_context: &'a mut NoteContext<'d>, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, } @@ -30,7 +30,7 @@ impl<'a, 'd> ThreadView<'a, 'd> { note_options: NoteOptions, is_muted: &'a MuteFun, note_context: &'a mut NoteContext<'d>, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, ) -> Self { let id_source = egui::Id::new("threadscroll_threadview"); @@ -135,10 +135,9 @@ impl<'a, 'd> ThreadView<'a, 'd> { } let zapping_acc = self - .cur_acc - .as_ref() - .filter(|_| self.note_context.current_account_has_wallet) - .or(self.cur_acc.as_ref()); + .note_context + .current_account_has_wallet + .then_some(self.cur_acc); show_notes( ui, diff --git a/crates/notedeck_columns/src/ui/timeline.rs b/crates/notedeck_columns/src/ui/timeline.rs @@ -21,7 +21,7 @@ pub struct TimelineView<'a, 'd> { reverse: bool, is_muted: &'a MuteFun, note_context: &'a mut NoteContext<'d>, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, } @@ -33,7 +33,7 @@ impl<'a, 'd> TimelineView<'a, 'd> { is_muted: &'a MuteFun, note_context: &'a mut NoteContext<'d>, note_options: NoteOptions, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, ) -> Self { let reverse = false; @@ -78,7 +78,7 @@ fn timeline_ui( note_options: NoteOptions, is_muted: &MuteFun, note_context: &mut NoteContext, - cur_acc: &Option<KeypairUnowned>, + cur_acc: &KeypairUnowned, jobs: &mut JobsCache, ) -> Option<NoteAction> { //padding(4.0, ui, |ui| ui.heading("Notifications")); @@ -337,7 +337,7 @@ pub struct TimelineTabView<'a, 'd> { txn: &'a Transaction, is_muted: &'a MuteFun, note_context: &'a mut NoteContext<'d>, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, } @@ -350,7 +350,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> { txn: &'a Transaction, is_muted: &'a MuteFun, note_context: &'a mut NoteContext<'d>, - cur_acc: &'a Option<KeypairUnowned<'a>>, + cur_acc: &'a KeypairUnowned<'a>, jobs: &'a mut JobsCache, ) -> Self { Self { @@ -407,11 +407,11 @@ impl<'a, 'd> TimelineTabView<'a, 'd> { }; if !muted { - let zapping_acc = self - .cur_acc - .as_ref() - .filter(|_| self.note_context.current_account_has_wallet) - .or(self.cur_acc.as_ref()); + let zapping_acc = if self.note_context.current_account_has_wallet { + Some(self.cur_acc) + } else { + None + }; notedeck_ui::padding(8.0, ui, |ui| { let resp = NoteView::new( diff --git a/crates/notedeck_columns/src/ui/wallet.rs b/crates/notedeck_columns/src/ui/wallet.rs @@ -92,13 +92,11 @@ impl WalletAction { global_wallet.ui_state.for_local_only = true; } WalletAction::Delete => { - if let Some(acc) = accounts.get_selected_account() { - if acc.wallet.is_some() { - accounts.update_current_account(|acc| { - acc.wallet = None; - }); - return None; - } + if accounts.get_selected_account().wallet.is_some() { + accounts.update_current_account(|acc| { + acc.wallet = None; + }); + return None; } global_wallet.wallet = None; diff --git a/crates/notedeck_dave/src/lib.rs b/crates/notedeck_dave/src/lib.rs @@ -209,11 +209,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr }; tracing::debug!("sending messages, latest: {:?}", messages.last().unwrap()); - let user_id = app_ctx - .accounts - .get_selected_account() - .map(|sa| calculate_user_id(sa.keypair())) - .unwrap_or_else(|| "unknown_user".to_string()); + let user_id = calculate_user_id(app_ctx.accounts.get_selected_account().keypair()); let ctx = ctx.clone(); let client = self.client.clone(); diff --git a/crates/notedeck_dave/src/ui/dave.rs b/crates/notedeck_dave/src/ui/dave.rs @@ -497,7 +497,9 @@ fn pfp_button<'me, 'a>( ndb: &Ndb, ) -> ProfilePic<'me, 'a> { let account = accounts.get_selected_account(); - let profile = account.and_then(|a| ndb.get_profile_by_pubkey(txn, a.key.pubkey.bytes()).ok()); + let profile = ndb + .get_profile_by_pubkey(txn, account.key.pubkey.bytes()) + .ok(); ProfilePic::from_profile_or_default(img_cache, profile.as_ref()) .size(24.0)