@@ -7,6 +7,7 @@ pub mod reply;
|
||||
pub mod reply_description;
|
||||
|
||||
pub use contents::NoteContents;
|
||||
use contents::NoteContext;
|
||||
pub use context::{NoteContextButton, NoteContextSelection};
|
||||
pub use options::NoteOptions;
|
||||
pub use post::{PostAction, PostResponse, PostType, PostView};
|
||||
@@ -25,14 +26,12 @@ use egui::emath::{pos2, Vec2};
|
||||
use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense};
|
||||
use enostr::{NoteId, Pubkey};
|
||||
use nostrdb::{Ndb, Note, NoteKey, Transaction};
|
||||
use notedeck::{CachedNote, Images, NoteCache, NotedeckTextStyle};
|
||||
use notedeck::{CachedNote, NoteCache, NotedeckTextStyle};
|
||||
|
||||
use super::profile::preview::one_line_display_name_widget;
|
||||
|
||||
pub struct NoteView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut Images,
|
||||
pub struct NoteView<'a, 'd> {
|
||||
note_context: &'a mut NoteContext<'d>,
|
||||
parent: Option<NoteKey>,
|
||||
note: &'a nostrdb::Note<'a>,
|
||||
flags: NoteOptions,
|
||||
@@ -64,17 +63,15 @@ impl NoteResponse {
|
||||
}
|
||||
}
|
||||
|
||||
impl View for NoteView<'_> {
|
||||
impl View for NoteView<'_, '_> {
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
self.show(ui);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> NoteView<'a> {
|
||||
impl<'a, 'd> NoteView<'a, 'd> {
|
||||
pub fn new(
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut Images,
|
||||
note_context: &'a mut NoteContext<'d>,
|
||||
note: &'a nostrdb::Note<'a>,
|
||||
mut flags: NoteOptions,
|
||||
) -> Self {
|
||||
@@ -83,9 +80,7 @@ impl<'a> NoteView<'a> {
|
||||
|
||||
let parent: Option<NoteKey> = None;
|
||||
Self {
|
||||
ndb,
|
||||
note_cache,
|
||||
img_cache,
|
||||
note_context,
|
||||
parent,
|
||||
note,
|
||||
flags,
|
||||
@@ -155,12 +150,16 @@ impl<'a> NoteView<'a> {
|
||||
let txn = self.note.txn().expect("todo: implement non-db notes");
|
||||
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
let profile = self
|
||||
.note_context
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
|
||||
//ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 2.0;
|
||||
|
||||
let cached_note = self
|
||||
.note_context
|
||||
.note_cache
|
||||
.cached_note_or_insert_mut(note_key, self.note);
|
||||
|
||||
@@ -180,9 +179,7 @@ impl<'a> NoteView<'a> {
|
||||
});
|
||||
|
||||
ui.add(&mut NoteContents::new(
|
||||
self.ndb,
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
self.note_context,
|
||||
txn,
|
||||
self.note,
|
||||
self.flags,
|
||||
@@ -231,14 +228,17 @@ impl<'a> NoteView<'a> {
|
||||
anim_speed,
|
||||
);
|
||||
|
||||
ui.put(rect, ui::ProfilePic::new(self.img_cache, pic).size(size))
|
||||
.on_hover_ui_at_pointer(|ui| {
|
||||
ui.set_max_width(300.0);
|
||||
ui.add(ui::ProfilePreview::new(
|
||||
profile.as_ref().unwrap(),
|
||||
self.img_cache,
|
||||
));
|
||||
});
|
||||
ui.put(
|
||||
rect,
|
||||
ui::ProfilePic::new(self.note_context.img_cache, pic).size(size),
|
||||
)
|
||||
.on_hover_ui_at_pointer(|ui| {
|
||||
ui.set_max_width(300.0);
|
||||
ui.add(ui::ProfilePreview::new(
|
||||
profile.as_ref().unwrap(),
|
||||
self.note_context.img_cache,
|
||||
));
|
||||
});
|
||||
|
||||
if resp.hovered() || resp.clicked() {
|
||||
ui::show_pointer(ui);
|
||||
@@ -254,7 +254,7 @@ impl<'a> NoteView<'a> {
|
||||
|
||||
ui.put(
|
||||
rect,
|
||||
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url())
|
||||
ui::ProfilePic::new(self.note_context.img_cache, ui::ProfilePic::no_pfp_url())
|
||||
.size(pfp_size),
|
||||
)
|
||||
.interact(sense)
|
||||
@@ -267,8 +267,11 @@ impl<'a> NoteView<'a> {
|
||||
NoteResponse::new(self.textmode_ui(ui))
|
||||
} else {
|
||||
let txn = self.note.txn().expect("txn");
|
||||
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());
|
||||
if let Some(note_to_repost) = get_reposted_note(self.note_context.ndb, txn, self.note) {
|
||||
let profile = self
|
||||
.note_context
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
|
||||
let style = NotedeckTextStyle::Small;
|
||||
ui.horizontal(|ui| {
|
||||
@@ -285,7 +288,7 @@ impl<'a> NoteView<'a> {
|
||||
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(ui::ProfilePreview::new(rec, self.note_context.img_cache));
|
||||
});
|
||||
}
|
||||
let color = ui.style().visuals.noninteractive().fg_stroke.color;
|
||||
@@ -296,14 +299,7 @@ impl<'a> NoteView<'a> {
|
||||
.text_style(style.text_style()),
|
||||
);
|
||||
});
|
||||
NoteView::new(
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.img_cache,
|
||||
¬e_to_repost,
|
||||
self.flags,
|
||||
)
|
||||
.show(ui)
|
||||
NoteView::new(self.note_context, ¬e_to_repost, self.flags).show(ui)
|
||||
} else {
|
||||
self.show_standard(ui)
|
||||
}
|
||||
@@ -340,7 +336,10 @@ impl<'a> NoteView<'a> {
|
||||
let mut selected_option: Option<NoteContextSelection> = None;
|
||||
|
||||
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
|
||||
let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
let profile = self
|
||||
.note_context
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
||||
|
||||
// wide design
|
||||
@@ -357,12 +356,18 @@ impl<'a> NoteView<'a> {
|
||||
ui.vertical(|ui| {
|
||||
ui.add_sized([size.x, self.options().pfp_size()], |ui: &mut egui::Ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
NoteView::note_header(ui, self.note_cache, self.note, &profile);
|
||||
NoteView::note_header(
|
||||
ui,
|
||||
self.note_context.note_cache,
|
||||
self.note,
|
||||
&profile,
|
||||
);
|
||||
})
|
||||
.response
|
||||
});
|
||||
|
||||
let note_reply = self
|
||||
.note_context
|
||||
.note_cache
|
||||
.cached_note_or_insert_mut(note_key, self.note)
|
||||
.reply
|
||||
@@ -371,15 +376,7 @@ impl<'a> NoteView<'a> {
|
||||
if note_reply.reply().is_some() {
|
||||
let action = ui
|
||||
.horizontal(|ui| {
|
||||
reply_desc(
|
||||
ui,
|
||||
txn,
|
||||
¬e_reply,
|
||||
self.ndb,
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
self.flags,
|
||||
)
|
||||
reply_desc(ui, txn, ¬e_reply, self.note_context, self.flags)
|
||||
})
|
||||
.inner;
|
||||
|
||||
@@ -390,14 +387,7 @@ impl<'a> NoteView<'a> {
|
||||
});
|
||||
});
|
||||
|
||||
let mut contents = NoteContents::new(
|
||||
self.ndb,
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
txn,
|
||||
self.note,
|
||||
self.options(),
|
||||
);
|
||||
let mut contents = NoteContents::new(self.note_context, txn, self.note, self.flags);
|
||||
|
||||
ui.add(&mut contents);
|
||||
|
||||
@@ -423,26 +413,20 @@ impl<'a> NoteView<'a> {
|
||||
};
|
||||
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||
NoteView::note_header(ui, self.note_cache, self.note, &profile);
|
||||
NoteView::note_header(ui, self.note_context.note_cache, self.note, &profile);
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 2.0;
|
||||
|
||||
let note_reply = self
|
||||
.note_context
|
||||
.note_cache
|
||||
.cached_note_or_insert_mut(note_key, self.note)
|
||||
.reply
|
||||
.borrow(self.note.tags());
|
||||
|
||||
if note_reply.reply().is_some() {
|
||||
let action = reply_desc(
|
||||
ui,
|
||||
txn,
|
||||
¬e_reply,
|
||||
self.ndb,
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
self.flags,
|
||||
);
|
||||
let action =
|
||||
reply_desc(ui, txn, ¬e_reply, self.note_context, self.flags);
|
||||
|
||||
if action.is_some() {
|
||||
note_action = action;
|
||||
@@ -450,14 +434,8 @@ impl<'a> NoteView<'a> {
|
||||
}
|
||||
});
|
||||
|
||||
let mut contents = NoteContents::new(
|
||||
self.ndb,
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
txn,
|
||||
self.note,
|
||||
self.options(),
|
||||
);
|
||||
let mut contents =
|
||||
NoteContents::new(self.note_context, txn, self.note, self.flags);
|
||||
ui.add(&mut contents);
|
||||
|
||||
if let Some(action) = contents.action() {
|
||||
@@ -490,8 +468,8 @@ impl<'a> NoteView<'a> {
|
||||
|
||||
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
|
||||
if let Ok(selection) = ThreadSelection::from_note_id(
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.note_context.ndb,
|
||||
self.note_context.note_cache,
|
||||
self.note.txn().unwrap(),
|
||||
NoteId::new(*self.note.id()),
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user