notedeck

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

route.rs (4013B)


      1 use crate::{
      2     nav::RenderNavAction,
      3     profile::ProfileAction,
      4     timeline::{thread::Threads, ThreadSelection, TimelineCache, TimelineKind},
      5     ui::{self, ProfileView},
      6 };
      7 
      8 use enostr::Pubkey;
      9 use notedeck::{JobsCache, NoteContext};
     10 use notedeck_ui::NoteOptions;
     11 
     12 #[allow(clippy::too_many_arguments)]
     13 pub fn render_timeline_route(
     14     timeline_cache: &mut TimelineCache,
     15     kind: &TimelineKind,
     16     col: usize,
     17     note_options: NoteOptions,
     18     depth: usize,
     19     ui: &mut egui::Ui,
     20     note_context: &mut NoteContext,
     21     jobs: &mut JobsCache,
     22     scroll_to_top: bool,
     23 ) -> Option<RenderNavAction> {
     24     match kind {
     25         TimelineKind::List(_)
     26         | TimelineKind::Search(_)
     27         | TimelineKind::Algo(_)
     28         | TimelineKind::Notifications(_)
     29         | TimelineKind::Universe
     30         | TimelineKind::Hashtag(_)
     31         | TimelineKind::Generic(_) => {
     32             let note_action =
     33                 ui::TimelineView::new(kind, timeline_cache, note_context, note_options, jobs, col)
     34                     .scroll_to_top(scroll_to_top)
     35                     .ui(ui);
     36 
     37             note_action.map(RenderNavAction::NoteAction)
     38         }
     39 
     40         TimelineKind::Profile(pubkey) => {
     41             if depth > 1 {
     42                 render_profile_route(
     43                     pubkey,
     44                     timeline_cache,
     45                     col,
     46                     ui,
     47                     note_options,
     48                     note_context,
     49                     jobs,
     50                 )
     51             } else {
     52                 // we render profiles like timelines if they are at the root
     53                 let note_action = ui::TimelineView::new(
     54                     kind,
     55                     timeline_cache,
     56                     note_context,
     57                     note_options,
     58                     jobs,
     59                     col,
     60                 )
     61                 .scroll_to_top(scroll_to_top)
     62                 .ui(ui);
     63 
     64                 note_action.map(RenderNavAction::NoteAction)
     65             }
     66         }
     67     }
     68 }
     69 
     70 #[allow(clippy::too_many_arguments)]
     71 pub fn render_thread_route(
     72     threads: &mut Threads,
     73     selection: &ThreadSelection,
     74     col: usize,
     75     mut note_options: NoteOptions,
     76     ui: &mut egui::Ui,
     77     note_context: &mut NoteContext,
     78     jobs: &mut JobsCache,
     79 ) -> Option<RenderNavAction> {
     80     // don't truncate thread notes for now, since they are
     81     // default truncated everywher eelse
     82     note_options.set(NoteOptions::Truncate, false);
     83 
     84     // We need the reply lines in threads
     85     note_options.set(NoteOptions::Wide, false);
     86 
     87     ui::ThreadView::new(
     88         threads,
     89         selection.selected_or_root(),
     90         note_options,
     91         note_context,
     92         jobs,
     93         col,
     94     )
     95     .ui(ui)
     96     .map(Into::into)
     97 }
     98 
     99 #[allow(clippy::too_many_arguments)]
    100 pub fn render_profile_route(
    101     pubkey: &Pubkey,
    102     timeline_cache: &mut TimelineCache,
    103     col: usize,
    104     ui: &mut egui::Ui,
    105     note_options: NoteOptions,
    106     note_context: &mut NoteContext,
    107     jobs: &mut JobsCache,
    108 ) -> Option<RenderNavAction> {
    109     let profile_view = ProfileView::new(
    110         pubkey,
    111         col,
    112         timeline_cache,
    113         note_options,
    114         note_context,
    115         jobs,
    116     )
    117     .ui(ui);
    118 
    119     if let Some(action) = profile_view {
    120         match action {
    121             ui::profile::ProfileViewAction::EditProfile => note_context
    122                 .accounts
    123                 .get_full(pubkey)
    124                 .map(|kp| RenderNavAction::ProfileAction(ProfileAction::Edit(kp.to_full()))),
    125             ui::profile::ProfileViewAction::Note(note_action) => {
    126                 Some(RenderNavAction::NoteAction(note_action))
    127             }
    128             ui::profile::ProfileViewAction::Follow(target_key) => Some(
    129                 RenderNavAction::ProfileAction(ProfileAction::Follow(target_key)),
    130             ),
    131             ui::profile::ProfileViewAction::Unfollow(target_key) => Some(
    132                 RenderNavAction::ProfileAction(ProfileAction::Unfollow(target_key)),
    133             ),
    134         }
    135     } else {
    136         None
    137     }
    138 }