notedeck

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

quote_repost.rs (2132B)


      1 use super::{PostResponse, PostType};
      2 use crate::{
      3     draft::Draft,
      4     ui::{self},
      5 };
      6 
      7 use egui::ScrollArea;
      8 use enostr::{FilledKeypair, NoteId};
      9 use notedeck::{JobsCache, NoteContext};
     10 use notedeck_ui::NoteOptions;
     11 
     12 pub struct QuoteRepostView<'a, 'd> {
     13     note_context: &'a mut NoteContext<'d>,
     14     poster: FilledKeypair<'a>,
     15     draft: &'a mut Draft,
     16     quoting_note: &'a nostrdb::Note<'a>,
     17     scroll_id: egui::Id,
     18     inner_rect: egui::Rect,
     19     note_options: NoteOptions,
     20     jobs: &'a mut JobsCache,
     21 }
     22 
     23 impl<'a, 'd> QuoteRepostView<'a, 'd> {
     24     #[allow(clippy::too_many_arguments)]
     25     pub fn new(
     26         note_context: &'a mut NoteContext<'d>,
     27         poster: FilledKeypair<'a>,
     28         draft: &'a mut Draft,
     29         quoting_note: &'a nostrdb::Note<'a>,
     30         inner_rect: egui::Rect,
     31         note_options: NoteOptions,
     32         jobs: &'a mut JobsCache,
     33         col: usize,
     34     ) -> Self {
     35         QuoteRepostView {
     36             note_context,
     37             poster,
     38             draft,
     39             quoting_note,
     40             scroll_id: QuoteRepostView::scroll_id(col, quoting_note.id()),
     41             inner_rect,
     42             note_options,
     43             jobs,
     44         }
     45     }
     46 
     47     fn id(col: usize, note_id: &[u8; 32]) -> egui::Id {
     48         egui::Id::new(("quote_repost", col, note_id))
     49     }
     50 
     51     pub fn scroll_id(col: usize, note_id: &[u8; 32]) -> egui::Id {
     52         QuoteRepostView::id(col, note_id).with("scroll")
     53     }
     54 
     55     pub fn show(&mut self, ui: &mut egui::Ui) -> PostResponse {
     56         ScrollArea::vertical()
     57             .id_salt(self.scroll_id)
     58             .show(ui, |ui| self.show_internal(ui))
     59             .inner
     60     }
     61 
     62     fn show_internal(&mut self, ui: &mut egui::Ui) -> PostResponse {
     63         let quoting_note_id = self.quoting_note.id();
     64 
     65         let post_resp = ui::PostView::new(
     66             self.note_context,
     67             self.draft,
     68             PostType::Quote(NoteId::new(quoting_note_id.to_owned())),
     69             self.poster,
     70             self.inner_rect,
     71             self.note_options,
     72             self.jobs,
     73         )
     74         .ui_no_scroll(self.quoting_note.txn().unwrap(), ui);
     75         post_resp
     76     }
     77 }