BIN
assets/icons/repost_icon_4x.png
Normal file
BIN
assets/icons/repost_icon_4x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 808 B |
7
queries/reposts.json
Normal file
7
queries/reposts.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"limit": 100,
|
||||||
|
"kinds": [
|
||||||
|
1, 6
|
||||||
|
],
|
||||||
|
"#p": ["32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"]
|
||||||
|
}
|
||||||
@@ -9,17 +9,14 @@ pub use post::{PostAction, PostResponse, PostView};
|
|||||||
pub use reply::PostReplyView;
|
pub use reply::PostReplyView;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
actionbar::BarAction,
|
actionbar::BarAction, app_style::NotedeckTextStyle, colors, imgcache::ImageCache, notecache::{CachedNote, NoteCache}, ui::{self, View}
|
||||||
colors,
|
|
||||||
imgcache::ImageCache,
|
|
||||||
notecache::{CachedNote, NoteCache},
|
|
||||||
ui,
|
|
||||||
ui::View,
|
|
||||||
};
|
};
|
||||||
use egui::{Label, RichText, Sense};
|
use egui::{Label, RichText, Sense};
|
||||||
use enostr::NoteId;
|
use enostr::NoteId;
|
||||||
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
|
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
|
||||||
|
|
||||||
|
use super::profile::preview::{get_display_name, one_line_display_name_widget};
|
||||||
|
|
||||||
pub struct NoteView<'a> {
|
pub struct NoteView<'a> {
|
||||||
ndb: &'a Ndb,
|
ndb: &'a Ndb,
|
||||||
note_cache: &'a mut NoteCache,
|
note_cache: &'a mut NoteCache,
|
||||||
@@ -325,7 +322,36 @@ impl<'a> NoteView<'a> {
|
|||||||
action: None,
|
action: None,
|
||||||
}
|
}
|
||||||
} else {
|
} 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(
|
fn render_note_actionbar(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
note_id: &[u8; 32],
|
note_id: &[u8; 32],
|
||||||
@@ -532,3 +588,8 @@ fn thread_button(ui: &mut egui::Ui, note_key: NoteKey) -> egui::Response {
|
|||||||
|
|
||||||
resp
|
resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn repost_icon() -> egui::Image<'static> {
|
||||||
|
let img_data = egui::include_image!("../../../assets/icons/repost_icon_4x.png");
|
||||||
|
egui::Image::new(img_data)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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 {
|
fn about_section_widget<'a>(profile: &'a ProfileRecord<'a>) -> impl egui::Widget + 'a {
|
||||||
|ui: &mut egui::Ui| {
|
|ui: &mut egui::Ui| {
|
||||||
if let Some(about) = profile.record().profile().and_then(|p| p.about()) {
|
if let Some(about) = profile.record().profile().and_then(|p| p.about()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user