toolbar.rs (2133B)
1 use notedeck::AppContext; 2 3 use crate::{ 4 timeline::{kind::ListKind, TimelineKind}, 5 Damus, Route, 6 }; 7 8 // TODO(kernelkind): should account for mutes 9 #[profiling::function] 10 pub fn unseen_notification( 11 columns: &mut Damus, 12 accounts: ¬edeck::Accounts, 13 active_col: usize, 14 ) -> bool { 15 let top = columns.columns(accounts).column(active_col).router().top(); 16 let current_pk = accounts.get_selected_account().keypair().pubkey; 17 18 if let Route::Timeline(TimelineKind::Notifications(notif_pk)) = top { 19 if notif_pk == current_pk { 20 return false; 21 } 22 } 23 24 let notif_kind = TimelineKind::Notifications(*current_pk); 25 let Some(tl) = columns.timeline_cache.get_mut(¬if_kind) else { 26 return false; 27 }; 28 29 !tl.seen_latest_notes 30 } 31 32 /// When you click the toolbar button, these actions 33 /// are returned 34 #[derive(Debug, Eq, PartialEq)] 35 pub enum ToolbarAction { 36 Notifications, 37 Search, 38 Home, 39 } 40 41 impl ToolbarAction { 42 pub fn process(&self, app: &mut Damus, ctx: &mut AppContext) { 43 let cur_acc_pk = ctx.accounts.get_selected_account().key.pubkey; 44 let route = match &self { 45 ToolbarAction::Notifications => { 46 Route::timeline(TimelineKind::Notifications(cur_acc_pk)) 47 } 48 ToolbarAction::Search => Route::Search, 49 ToolbarAction::Home => { 50 Route::timeline(TimelineKind::List(ListKind::Contact(cur_acc_pk))) 51 } 52 }; 53 54 let Some(cols) = app.decks_cache.active_columns_mut(ctx.i18n, ctx.accounts) else { 55 return; 56 }; 57 58 match cols.select_by_route(route) { 59 crate::column::SelectionResult::AlreadySelected(_) => {} // great! no need to go to top yet 60 crate::column::SelectionResult::NewSelection(_) => { 61 // we already selected this, so scroll to top 62 app.scroll_to_top(); 63 } 64 crate::column::SelectionResult::Failed => { 65 // oh no, something went wrong 66 // TODO(jb55): handle tab selection failure 67 } 68 } 69 } 70 }