notedeck

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

quote_repost.rs (1944B)


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