From f2993a61b7c1f508e32057d213abca60e4805521 Mon Sep 17 00:00:00 2001 From: kernelkind Date: Thu, 12 Sep 2024 17:06:10 -0400 Subject: [PATCH] kind 6 repost impl Signed-off-by: kernelkind --- assets/icons/repost_icon_4x.png | Bin 0 -> 808 bytes queries/reposts.json | 7 +++ src/ui/note/mod.rs | 75 +++++++++++++++++++++++++++++--- src/ui/profile/preview.rs | 15 +++++++ 4 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 assets/icons/repost_icon_4x.png create mode 100644 queries/reposts.json diff --git a/assets/icons/repost_icon_4x.png b/assets/icons/repost_icon_4x.png new file mode 100644 index 0000000000000000000000000000000000000000..6573f8f136805cb3e1be0b6d111c427f07078dc7 GIT binary patch literal 808 zcmV+@1K0eCP)@~0drDELIAGL9O(c600d`2O+f$vv5yPp9$!k1c3G6^v7 z3V?1Oe&?-*M9}Tx@?KuYt22CyQCke}`>%bTxE#jt7B>G@4^W`eayX}OW;GzdUbt@! z%4i926)1Qaxqb(3cP3OJ4nRmd!_$PQrXtdkW2rz9bUiUd1DQyJARjWwiSER>r~SBJ zpvyNQJ-g0gXw1L2(YRUyyoLQK;)7p}oPY{n&l{b!kbkWzHdSzo337XuaV zG4H6`x&JjfR0zqBIU&;0$L&e-5!@7XgbaM^@k6{%yycJgb(rA4MH)iuRZtT6a@E&B miFgrIkHr{ { ndb: &'a Ndb, note_cache: &'a mut NoteCache, @@ -325,7 +322,36 @@ impl<'a> NoteView<'a> { action: None, } } else { - self.show_standard(ui) + let txn = self.note.txn().expect("todo: support non-db notes"); + if let Some(note_key) = get_reposted_note_key(self.ndb, txn, self.note) { + let note = self.ndb.get_note_by_key(txn, note_key).unwrap(); + let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey()); + + ui.horizontal(|ui| { + ui.vertical(|ui| { + ui.add_space(2.0); + ui.add_sized([20.0, 20.0], repost_icon()); + }); + ui.add_space(6.0); + let resp = ui.add(one_line_display_name_widget(get_display_name( + profile.as_ref().ok(), + ))); + if let Ok(rec) = &profile { + resp.on_hover_ui_at_pointer(|ui| { + ui.set_max_width(300.0); + ui.add(ui::ProfilePreview::new(rec, self.img_cache)); + }); + } + ui.add_space(4.0); + ui.label( + RichText::new("Reposted") + .text_style(NotedeckTextStyle::Heading3.text_style()), + ); + }); + NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e).show(ui) + } else { + self.show_standard(ui) + } } } @@ -445,6 +471,36 @@ impl<'a> NoteView<'a> { } } +fn get_reposted_note_key(ndb: &Ndb, txn: &Transaction, note: &Note) -> Option { + let new_note_id: &[u8; 32] = if note.kind() == 6 { + let mut res = None; + for tag in note.tags().iter() { + if let Some(tag_str) = tag.get(0).unwrap().variant().str() { + if tag_str == "e" { + if let Some(note_id) = tag.get(1).and_then(|f| f.variant().id()) { + res = Some(note_id); + break; + } + } + } + } + res? + } else { + return None; + }; + + let note = ndb.get_note_by_id(txn, new_note_id).ok(); + if let Some(note) = note { + if note.kind() == 1 { + note.key() + } else { + None + } + } else { + None + } +} + fn render_note_actionbar( ui: &mut egui::Ui, note_id: &[u8; 32], @@ -532,3 +588,8 @@ fn thread_button(ui: &mut egui::Ui, note_key: NoteKey) -> egui::Response { resp } + +fn repost_icon() -> egui::Image<'static> { + let img_data = egui::include_image!("../../../assets/icons/repost_icon_4x.png"); + egui::Image::new(img_data) +} diff --git a/src/ui/profile/preview.rs b/src/ui/profile/preview.rs index bc826723..42ea7b27 100644 --- a/src/ui/profile/preview.rs +++ b/src/ui/profile/preview.rs @@ -198,6 +198,21 @@ fn display_name_widget( } } +pub fn one_line_display_name_widget(display_name: DisplayName<'_>) -> impl egui::Widget + '_ { + move |ui: &mut egui::Ui| match display_name { + DisplayName::One(n) => { + ui.label(RichText::new(n).text_style(NotedeckTextStyle::Heading3.text_style())) + } + + DisplayName::Both { + display_name, + username: _, + } => ui.label( + RichText::new(display_name).text_style(NotedeckTextStyle::Heading3.text_style()), + ), + } +} + fn about_section_widget<'a>(profile: &'a ProfileRecord<'a>) -> impl egui::Widget + 'a { |ui: &mut egui::Ui| { if let Some(about) = profile.record().profile().and_then(|p| p.about()) {