@@ -9,17 +9,14 @@ pub use post::{PostAction, PostResponse, PostView};
|
||||
pub use reply::PostReplyView;
|
||||
|
||||
use crate::{
|
||||
actionbar::BarAction,
|
||||
colors,
|
||||
imgcache::ImageCache,
|
||||
notecache::{CachedNote, NoteCache},
|
||||
ui,
|
||||
ui::View,
|
||||
actionbar::BarAction, app_style::NotedeckTextStyle, colors, imgcache::ImageCache, notecache::{CachedNote, NoteCache}, ui::{self, View}
|
||||
};
|
||||
use egui::{Label, RichText, Sense};
|
||||
use enostr::NoteId;
|
||||
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
|
||||
|
||||
use super::profile::preview::{get_display_name, one_line_display_name_widget};
|
||||
|
||||
pub struct NoteView<'a> {
|
||||
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<NoteKey> {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user