route.rs (4898B)
1 use crate::{ 2 column::Columns, 3 draft::Drafts, 4 nav::RenderNavAction, 5 notes_holder::NotesHolderStorage, 6 profile::Profile, 7 thread::Thread, 8 timeline::{TimelineId, TimelineKind}, 9 ui::{ 10 self, 11 note::{NoteOptions, QuoteRepostView}, 12 profile::ProfileView, 13 }, 14 }; 15 16 use enostr::{NoteId, Pubkey}; 17 use nostrdb::{Ndb, Transaction}; 18 use notedeck::{Accounts, ImageCache, MuteFun, NoteCache, UnknownIds}; 19 20 #[derive(Debug, Eq, PartialEq, Clone, Copy)] 21 pub enum TimelineRoute { 22 Timeline(TimelineId), 23 Thread(NoteId), 24 Profile(Pubkey), 25 Reply(NoteId), 26 Quote(NoteId), 27 } 28 29 #[allow(clippy::too_many_arguments)] 30 pub fn render_timeline_route( 31 ndb: &Ndb, 32 columns: &mut Columns, 33 drafts: &mut Drafts, 34 img_cache: &mut ImageCache, 35 unknown_ids: &mut UnknownIds, 36 note_cache: &mut NoteCache, 37 threads: &mut NotesHolderStorage<Thread>, 38 profiles: &mut NotesHolderStorage<Profile>, 39 accounts: &mut Accounts, 40 route: TimelineRoute, 41 col: usize, 42 textmode: bool, 43 ui: &mut egui::Ui, 44 ) -> Option<RenderNavAction> { 45 match route { 46 TimelineRoute::Timeline(timeline_id) => { 47 let note_options = { 48 let is_universe = if let Some(timeline) = columns.find_timeline(timeline_id) { 49 timeline.kind == TimelineKind::Universe 50 } else { 51 false 52 }; 53 54 let mut options = NoteOptions::new(is_universe); 55 options.set_textmode(textmode); 56 options 57 }; 58 59 let note_action = ui::TimelineView::new( 60 timeline_id, 61 columns, 62 ndb, 63 note_cache, 64 img_cache, 65 note_options, 66 ) 67 .ui(ui); 68 69 note_action.map(RenderNavAction::NoteAction) 70 } 71 72 TimelineRoute::Thread(id) => ui::ThreadView::new( 73 threads, 74 ndb, 75 note_cache, 76 unknown_ids, 77 img_cache, 78 id.bytes(), 79 textmode, 80 ) 81 .id_source(egui::Id::new(("threadscroll", col))) 82 .ui(ui, &accounts.mutefun()) 83 .map(Into::into), 84 85 TimelineRoute::Reply(id) => { 86 let txn = if let Ok(txn) = Transaction::new(ndb) { 87 txn 88 } else { 89 ui.label("Reply to unknown note"); 90 return None; 91 }; 92 93 let note = if let Ok(note) = ndb.get_note_by_id(&txn, id.bytes()) { 94 note 95 } else { 96 ui.label("Reply to unknown note"); 97 return None; 98 }; 99 100 let id = egui::Id::new(("post", col, note.key().unwrap())); 101 let poster = accounts.selected_or_first_nsec()?; 102 103 let action = { 104 let draft = drafts.reply_mut(note.id()); 105 106 let response = egui::ScrollArea::vertical().show(ui, |ui| { 107 ui::PostReplyView::new(ndb, poster, draft, note_cache, img_cache, ¬e) 108 .id_source(id) 109 .show(ui) 110 }); 111 112 response.inner.action 113 }; 114 115 action.map(Into::into) 116 } 117 118 TimelineRoute::Profile(pubkey) => render_profile_route( 119 &pubkey, 120 ndb, 121 profiles, 122 img_cache, 123 note_cache, 124 col, 125 ui, 126 &accounts.mutefun(), 127 ), 128 129 TimelineRoute::Quote(id) => { 130 let txn = Transaction::new(ndb).expect("txn"); 131 132 let note = if let Ok(note) = ndb.get_note_by_id(&txn, id.bytes()) { 133 note 134 } else { 135 ui.label("Quote of unknown note"); 136 return None; 137 }; 138 139 let id = egui::Id::new(("post", col, note.key().unwrap())); 140 141 let poster = accounts.selected_or_first_nsec()?; 142 let draft = drafts.quote_mut(note.id()); 143 144 let response = egui::ScrollArea::vertical().show(ui, |ui| { 145 QuoteRepostView::new(ndb, poster, note_cache, img_cache, draft, ¬e) 146 .id_source(id) 147 .show(ui) 148 }); 149 150 response.inner.action.map(Into::into) 151 } 152 } 153 } 154 155 #[allow(clippy::too_many_arguments)] 156 pub fn render_profile_route( 157 pubkey: &Pubkey, 158 ndb: &Ndb, 159 profiles: &mut NotesHolderStorage<Profile>, 160 img_cache: &mut ImageCache, 161 note_cache: &mut NoteCache, 162 col: usize, 163 ui: &mut egui::Ui, 164 is_muted: &MuteFun, 165 ) -> Option<RenderNavAction> { 166 let note_action = ProfileView::new( 167 pubkey, 168 col, 169 profiles, 170 ndb, 171 note_cache, 172 img_cache, 173 NoteOptions::default(), 174 ) 175 .ui(ui, is_muted); 176 177 note_action.map(RenderNavAction::NoteAction) 178 }