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