notedeck

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

mod.rs (2874B)


      1 pub mod picture;
      2 pub mod preview;
      3 
      4 use crate::notes_holder::NotesHolder;
      5 use crate::ui::note::NoteOptions;
      6 use egui::{ScrollArea, Widget};
      7 use enostr::Pubkey;
      8 use nostrdb::{Ndb, Transaction};
      9 pub use picture::ProfilePic;
     10 pub use preview::ProfilePreview;
     11 use tracing::error;
     12 
     13 use crate::{actionbar::NoteAction, notes_holder::NotesHolderStorage, profile::Profile};
     14 
     15 use super::timeline::{tabs_ui, TimelineTabView};
     16 use notedeck::{ImageCache, MuteFun, NoteCache};
     17 
     18 pub struct ProfileView<'a> {
     19     pubkey: &'a Pubkey,
     20     col_id: usize,
     21     profiles: &'a mut NotesHolderStorage<Profile>,
     22     note_options: NoteOptions,
     23     ndb: &'a Ndb,
     24     note_cache: &'a mut NoteCache,
     25     img_cache: &'a mut ImageCache,
     26 }
     27 
     28 impl<'a> ProfileView<'a> {
     29     pub fn new(
     30         pubkey: &'a Pubkey,
     31         col_id: usize,
     32         profiles: &'a mut NotesHolderStorage<Profile>,
     33         ndb: &'a Ndb,
     34         note_cache: &'a mut NoteCache,
     35         img_cache: &'a mut ImageCache,
     36         note_options: NoteOptions,
     37     ) -> Self {
     38         ProfileView {
     39             pubkey,
     40             col_id,
     41             profiles,
     42             ndb,
     43             note_cache,
     44             img_cache,
     45             note_options,
     46         }
     47     }
     48 
     49     pub fn ui(&mut self, ui: &mut egui::Ui, is_muted: &MuteFun) -> Option<NoteAction> {
     50         let scroll_id = egui::Id::new(("profile_scroll", self.col_id, self.pubkey));
     51 
     52         ScrollArea::vertical()
     53             .id_salt(scroll_id)
     54             .show(ui, |ui| {
     55                 let txn = Transaction::new(self.ndb).expect("txn");
     56                 if let Ok(profile) = self.ndb.get_profile_by_pubkey(&txn, self.pubkey.bytes()) {
     57                     ProfilePreview::new(&profile, self.img_cache).ui(ui);
     58                 }
     59                 let profile = self
     60                     .profiles
     61                     .notes_holder_mutated(
     62                         self.ndb,
     63                         self.note_cache,
     64                         &txn,
     65                         self.pubkey.bytes(),
     66                         is_muted,
     67                     )
     68                     .get_ptr();
     69 
     70                 profile.timeline.selected_view =
     71                     tabs_ui(ui, profile.timeline.selected_view, &profile.timeline.views);
     72 
     73                 // poll for new notes and insert them into our existing notes
     74                 if let Err(e) = profile.poll_notes_into_view(&txn, self.ndb, is_muted) {
     75                     error!("Profile::poll_notes_into_view: {e}");
     76                 }
     77 
     78                 let reversed = false;
     79 
     80                 TimelineTabView::new(
     81                     profile.timeline.current_view(),
     82                     reversed,
     83                     self.note_options,
     84                     &txn,
     85                     self.ndb,
     86                     self.note_cache,
     87                     self.img_cache,
     88                 )
     89                 .show(ui)
     90             })
     91             .inner
     92     }
     93 }