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