notedeck

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

quote_repost.rs (1641B)


      1 use enostr::{FilledKeypair, NoteId};
      2 use nostrdb::Ndb;
      3 use notedeck::{ImageCache, NoteCache};
      4 
      5 use crate::{draft::Draft, ui};
      6 
      7 use super::{PostResponse, PostType};
      8 
      9 pub struct QuoteRepostView<'a> {
     10     ndb: &'a Ndb,
     11     poster: FilledKeypair<'a>,
     12     note_cache: &'a mut NoteCache,
     13     img_cache: &'a mut ImageCache,
     14     draft: &'a mut Draft,
     15     quoting_note: &'a nostrdb::Note<'a>,
     16     id_source: Option<egui::Id>,
     17 }
     18 
     19 impl<'a> QuoteRepostView<'a> {
     20     pub fn new(
     21         ndb: &'a Ndb,
     22         poster: FilledKeypair<'a>,
     23         note_cache: &'a mut NoteCache,
     24         img_cache: &'a mut ImageCache,
     25         draft: &'a mut Draft,
     26         quoting_note: &'a nostrdb::Note<'a>,
     27     ) -> Self {
     28         let id_source: Option<egui::Id> = None;
     29         QuoteRepostView {
     30             ndb,
     31             poster,
     32             note_cache,
     33             img_cache,
     34             draft,
     35             quoting_note,
     36             id_source,
     37         }
     38     }
     39 
     40     pub fn show(&mut self, ui: &mut egui::Ui) -> PostResponse {
     41         let id = self.id();
     42         let quoting_note_id = self.quoting_note.id();
     43 
     44         ui::PostView::new(
     45             self.ndb,
     46             self.draft,
     47             PostType::Quote(NoteId::new(quoting_note_id.to_owned())),
     48             self.img_cache,
     49             self.note_cache,
     50             self.poster,
     51         )
     52         .id_source(id)
     53         .ui(self.quoting_note.txn().unwrap(), ui)
     54     }
     55 
     56     pub fn id_source(mut self, id: egui::Id) -> Self {
     57         self.id_source = Some(id);
     58         self
     59     }
     60 
     61     pub fn id(&self) -> egui::Id {
     62         self.id_source
     63             .unwrap_or_else(|| egui::Id::new("quote-repost-view"))
     64     }
     65 }