From 06aa595d54f2580c0b29b87fd11b167bd823b0ca Mon Sep 17 00:00:00 2001 From: kernelkind Date: Tue, 17 Sep 2024 11:12:43 -0400 Subject: [PATCH] add suggested changes Signed-off-by: kernelkind --- src/ui/note/mod.rs | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/ui/note/mod.rs b/src/ui/note/mod.rs index 25bb9b2..3042688 100644 --- a/src/ui/note/mod.rs +++ b/src/ui/note/mod.rs @@ -9,7 +9,12 @@ pub use post::{PostAction, PostResponse, PostView}; pub use reply::PostReplyView; use crate::{ - actionbar::BarAction, app_style::NotedeckTextStyle, colors, imgcache::ImageCache, notecache::{CachedNote, NoteCache}, ui::{self, View} + actionbar::BarAction, + app_style::NotedeckTextStyle, + colors, + imgcache::ImageCache, + notecache::{CachedNote, NoteCache}, + ui::{self, View}, }; use egui::{Label, RichText, Sense}; use enostr::NoteId; @@ -323,8 +328,7 @@ impl<'a> NoteView<'a> { } } else { 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(); + if let Some(note_to_repost) = get_reposted_note(self.ndb, txn, self.note) { let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey()); ui.horizontal(|ui| { @@ -348,7 +352,7 @@ impl<'a> NoteView<'a> { .text_style(NotedeckTextStyle::Heading3.text_style()), ); }); - NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e).show(ui) + NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e_to_repost).show(ui) } else { self.show_standard(ui) } @@ -471,16 +475,18 @@ impl<'a> NoteView<'a> { } } -fn get_reposted_note_key(ndb: &Ndb, txn: &Transaction, note: &Note) -> Option { +fn get_reposted_note<'a>(ndb: &Ndb, txn: &'a 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; - } + if tag.count() == 0 { + continue; + } + + if let Some("e") = tag.get(0).and_then(|t| t.variant().str()) { + if let Some(note_id) = tag.get(1).and_then(|f| f.variant().id()) { + res = Some(note_id); + break; } } } @@ -490,15 +496,7 @@ fn get_reposted_note_key(ndb: &Ndb, txn: &Transaction, note: &Note) -> Option