@@ -11,33 +11,33 @@ use tracing::warn;
|
||||
|
||||
use notedeck::{supported_mime_hosted_at_url, Images, MediaCacheType, NoteCache};
|
||||
|
||||
pub struct NoteContents<'a> {
|
||||
ndb: &'a Ndb,
|
||||
img_cache: &'a mut Images,
|
||||
note_cache: &'a mut NoteCache,
|
||||
/// Aggregates dependencies to reduce the number of parameters
|
||||
/// passed to inner UI elements, minimizing prop drilling.
|
||||
pub struct NoteContentsDriller<'d> {
|
||||
pub ndb: &'d Ndb,
|
||||
pub img_cache: &'d mut Images,
|
||||
pub note_cache: &'d mut NoteCache,
|
||||
pub options: NoteOptions,
|
||||
}
|
||||
|
||||
pub struct NoteContents<'a, 'd> {
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
txn: &'a Transaction,
|
||||
note: &'a Note<'a>,
|
||||
options: NoteOptions,
|
||||
action: Option<NoteAction>,
|
||||
}
|
||||
|
||||
impl<'a> NoteContents<'a> {
|
||||
impl<'a, 'd> NoteContents<'a, 'd> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
ndb: &'a Ndb,
|
||||
img_cache: &'a mut Images,
|
||||
note_cache: &'a mut NoteCache,
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
txn: &'a Transaction,
|
||||
note: &'a Note,
|
||||
options: ui::note::NoteOptions,
|
||||
) -> Self {
|
||||
NoteContents {
|
||||
ndb,
|
||||
img_cache,
|
||||
note_cache,
|
||||
driller,
|
||||
txn,
|
||||
note,
|
||||
options,
|
||||
action: None,
|
||||
}
|
||||
}
|
||||
@@ -47,17 +47,9 @@ impl<'a> NoteContents<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl egui::Widget for &mut NoteContents<'_> {
|
||||
impl egui::Widget for &mut NoteContents<'_, '_> {
|
||||
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||||
let result = render_note_contents(
|
||||
ui,
|
||||
self.ndb,
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
self.txn,
|
||||
self.note,
|
||||
self.options,
|
||||
);
|
||||
let result = render_note_contents(ui, self.driller, self.txn, self.note);
|
||||
self.action = result.action;
|
||||
result.response
|
||||
}
|
||||
@@ -68,18 +60,15 @@ impl egui::Widget for &mut NoteContents<'_> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn render_note_preview(
|
||||
ui: &mut egui::Ui,
|
||||
ndb: &Ndb,
|
||||
note_cache: &mut NoteCache,
|
||||
img_cache: &mut Images,
|
||||
driller: &mut NoteContentsDriller,
|
||||
txn: &Transaction,
|
||||
id: &[u8; 32],
|
||||
parent: NoteKey,
|
||||
note_options: NoteOptions,
|
||||
) -> NoteResponse {
|
||||
#[cfg(feature = "profiling")]
|
||||
puffin::profile_function!();
|
||||
|
||||
let note = if let Ok(note) = ndb.get_note_by_id(txn, id) {
|
||||
let note = if let Ok(note) = driller.ndb.get_note_by_id(txn, id) {
|
||||
// TODO: support other preview kinds
|
||||
if note.kind() == 1 {
|
||||
note
|
||||
@@ -112,7 +101,7 @@ pub fn render_note_preview(
|
||||
ui.visuals().noninteractive().bg_stroke.color,
|
||||
))
|
||||
.show(ui, |ui| {
|
||||
ui::NoteView::new(ndb, note_cache, img_cache, ¬e, note_options)
|
||||
ui::NoteView::new(driller, ¬e)
|
||||
.actionbar(false)
|
||||
.small_pfp(true)
|
||||
.wide(true)
|
||||
@@ -127,26 +116,23 @@ pub fn render_note_preview(
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn render_note_contents(
|
||||
ui: &mut egui::Ui,
|
||||
ndb: &Ndb,
|
||||
img_cache: &mut Images,
|
||||
note_cache: &mut NoteCache,
|
||||
driller: &mut NoteContentsDriller,
|
||||
txn: &Transaction,
|
||||
note: &Note,
|
||||
options: NoteOptions,
|
||||
) -> NoteResponse {
|
||||
#[cfg(feature = "profiling")]
|
||||
puffin::profile_function!();
|
||||
|
||||
let note_key = note.key().expect("todo: implement non-db notes");
|
||||
let selectable = options.has_selectable_text();
|
||||
let selectable = driller.options.has_selectable_text();
|
||||
let mut images: Vec<(String, MediaCacheType)> = vec![];
|
||||
let mut note_action: Option<NoteAction> = None;
|
||||
let mut inline_note: Option<(&[u8; 32], &str)> = None;
|
||||
let hide_media = options.has_hide_media();
|
||||
let hide_media = driller.options.has_hide_media();
|
||||
let link_color = ui.visuals().hyperlink_color;
|
||||
|
||||
let response = ui.horizontal_wrapped(|ui| {
|
||||
let blocks = if let Ok(blocks) = ndb.get_blocks_by_key(txn, note_key) {
|
||||
let blocks = if let Ok(blocks) = driller.ndb.get_blocks_by_key(txn, note_key) {
|
||||
blocks
|
||||
} else {
|
||||
warn!("missing note content blocks? '{}'", note.content());
|
||||
@@ -160,28 +146,30 @@ fn render_note_contents(
|
||||
match block.blocktype() {
|
||||
BlockType::MentionBech32 => match block.as_mention().unwrap() {
|
||||
Mention::Profile(profile) => {
|
||||
let act = ui::Mention::new(ndb, img_cache, txn, profile.pubkey())
|
||||
.show(ui)
|
||||
.inner;
|
||||
let act =
|
||||
ui::Mention::new(driller.ndb, driller.img_cache, txn, profile.pubkey())
|
||||
.show(ui)
|
||||
.inner;
|
||||
if act.is_some() {
|
||||
note_action = act;
|
||||
}
|
||||
}
|
||||
|
||||
Mention::Pubkey(npub) => {
|
||||
let act = ui::Mention::new(ndb, img_cache, txn, npub.pubkey())
|
||||
.show(ui)
|
||||
.inner;
|
||||
let act =
|
||||
ui::Mention::new(driller.ndb, driller.img_cache, txn, npub.pubkey())
|
||||
.show(ui)
|
||||
.inner;
|
||||
if act.is_some() {
|
||||
note_action = act;
|
||||
}
|
||||
}
|
||||
|
||||
Mention::Note(note) if options.has_note_previews() => {
|
||||
Mention::Note(note) if driller.options.has_note_previews() => {
|
||||
inline_note = Some((note.id(), block.as_str()));
|
||||
}
|
||||
|
||||
Mention::Event(note) if options.has_note_previews() => {
|
||||
Mention::Event(note) if driller.options.has_note_previews() => {
|
||||
inline_note = Some((note.id(), block.as_str()));
|
||||
}
|
||||
|
||||
@@ -208,7 +196,7 @@ fn render_note_contents(
|
||||
let mut found_supported = || -> bool {
|
||||
let url = block.as_str();
|
||||
if let Some(cache_type) =
|
||||
supported_mime_hosted_at_url(&mut img_cache.urls, url)
|
||||
supported_mime_hosted_at_url(&mut driller.img_cache.urls, url)
|
||||
{
|
||||
images.push((url.to_string(), cache_type));
|
||||
true
|
||||
@@ -229,7 +217,7 @@ fn render_note_contents(
|
||||
BlockType::Text => {
|
||||
#[cfg(feature = "profiling")]
|
||||
puffin::profile_scope!("text contents");
|
||||
if options.has_scramble_text() {
|
||||
if driller.options.has_scramble_text() {
|
||||
ui.add(egui::Label::new(rot13(block.as_str())).selectable(selectable));
|
||||
} else {
|
||||
ui.add(egui::Label::new(block.as_str()).selectable(selectable));
|
||||
@@ -244,15 +232,15 @@ fn render_note_contents(
|
||||
});
|
||||
|
||||
let preview_note_action = if let Some((id, _block_str)) = inline_note {
|
||||
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, note_key, options).action
|
||||
render_note_preview(ui, driller, txn, id, note_key).action
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if !images.is_empty() && !options.has_textmode() {
|
||||
if !images.is_empty() && !driller.options.has_textmode() {
|
||||
ui.add_space(2.0);
|
||||
let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note")));
|
||||
image_carousel(ui, img_cache, images, carousel_id);
|
||||
image_carousel(ui, driller.img_cache, images, carousel_id);
|
||||
ui.add_space(2.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ pub mod reply;
|
||||
pub mod reply_description;
|
||||
|
||||
pub use contents::NoteContents;
|
||||
use contents::NoteContentsDriller;
|
||||
pub use context::{NoteContextButton, NoteContextSelection};
|
||||
pub use options::NoteOptions;
|
||||
pub use post::{PostAction, PostResponse, PostType, PostView};
|
||||
@@ -25,17 +26,14 @@ 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> {
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
parent: Option<NoteKey>,
|
||||
note: &'a nostrdb::Note<'a>,
|
||||
flags: NoteOptions,
|
||||
}
|
||||
|
||||
pub struct NoteResponse {
|
||||
@@ -64,31 +62,22 @@ 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> {
|
||||
pub fn new(
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut Images,
|
||||
note: &'a nostrdb::Note<'a>,
|
||||
mut flags: NoteOptions,
|
||||
) -> Self {
|
||||
flags.set_actionbar(true);
|
||||
flags.set_note_previews(true);
|
||||
impl<'a, 'd> NoteView<'a, 'd> {
|
||||
pub fn new(driller: &'a mut NoteContentsDriller<'d>, note: &'a nostrdb::Note<'a>) -> Self {
|
||||
driller.options.set_actionbar(true);
|
||||
driller.options.set_note_previews(true);
|
||||
|
||||
let parent: Option<NoteKey> = None;
|
||||
Self {
|
||||
ndb,
|
||||
note_cache,
|
||||
img_cache,
|
||||
driller,
|
||||
parent,
|
||||
note,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,11 +122,11 @@ impl<'a> NoteView<'a> {
|
||||
}
|
||||
|
||||
pub fn options(&self) -> NoteOptions {
|
||||
self.flags
|
||||
self.driller.options
|
||||
}
|
||||
|
||||
pub fn options_mut(&mut self) -> &mut NoteOptions {
|
||||
&mut self.flags
|
||||
&mut self.driller.options
|
||||
}
|
||||
|
||||
pub fn parent(mut self, parent: NoteKey) -> Self {
|
||||
@@ -150,12 +139,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
|
||||
.driller
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
|
||||
//ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 2.0;
|
||||
|
||||
let cached_note = self
|
||||
.driller
|
||||
.note_cache
|
||||
.cached_note_or_insert_mut(note_key, self.note);
|
||||
|
||||
@@ -174,14 +167,7 @@ impl<'a> NoteView<'a> {
|
||||
)
|
||||
});
|
||||
|
||||
ui.add(&mut NoteContents::new(
|
||||
self.ndb,
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
txn,
|
||||
self.note,
|
||||
self.flags,
|
||||
));
|
||||
ui.add(&mut NoteContents::new(self.driller, txn, self.note));
|
||||
//});
|
||||
})
|
||||
.response
|
||||
@@ -226,14 +212,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.driller.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.driller.img_cache,
|
||||
));
|
||||
});
|
||||
|
||||
if resp.hovered() || resp.clicked() {
|
||||
ui::show_pointer(ui);
|
||||
@@ -249,7 +238,7 @@ impl<'a> NoteView<'a> {
|
||||
|
||||
ui.put(
|
||||
rect,
|
||||
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url())
|
||||
ui::ProfilePic::new(self.driller.img_cache, ui::ProfilePic::no_pfp_url())
|
||||
.size(pfp_size),
|
||||
)
|
||||
.interact(sense)
|
||||
@@ -262,8 +251,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.driller.ndb, txn, self.note) {
|
||||
let profile = self
|
||||
.driller
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
|
||||
let style = NotedeckTextStyle::Small;
|
||||
ui.horizontal(|ui| {
|
||||
@@ -280,7 +272,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.driller.img_cache));
|
||||
});
|
||||
}
|
||||
let color = ui.style().visuals.noninteractive().fg_stroke.color;
|
||||
@@ -291,14 +283,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.driller, ¬e_to_repost).show(ui)
|
||||
} else {
|
||||
self.show_standard(ui)
|
||||
}
|
||||
@@ -352,7 +337,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
|
||||
.driller
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
||||
let container_right = {
|
||||
let r = ui.available_rect_before_wrap();
|
||||
@@ -377,7 +365,7 @@ impl<'a> NoteView<'a> {
|
||||
ui.horizontal_centered(|ui| {
|
||||
selected_option = NoteView::note_header(
|
||||
ui,
|
||||
self.note_cache,
|
||||
self.driller.note_cache,
|
||||
self.note,
|
||||
&profile,
|
||||
self.options(),
|
||||
@@ -389,6 +377,7 @@ impl<'a> NoteView<'a> {
|
||||
});
|
||||
|
||||
let note_reply = self
|
||||
.driller
|
||||
.note_cache
|
||||
.cached_note_or_insert_mut(note_key, self.note)
|
||||
.reply
|
||||
@@ -396,17 +385,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,
|
||||
)
|
||||
})
|
||||
.horizontal(|ui| reply_desc(ui, txn, ¬e_reply, self.driller))
|
||||
.inner;
|
||||
|
||||
if action.is_some() {
|
||||
@@ -416,14 +395,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.driller, txn, self.note);
|
||||
|
||||
ui.add(&mut contents);
|
||||
|
||||
@@ -451,7 +423,7 @@ impl<'a> NoteView<'a> {
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||
selected_option = NoteView::note_header(
|
||||
ui,
|
||||
self.note_cache,
|
||||
self.driller.note_cache,
|
||||
self.note,
|
||||
&profile,
|
||||
self.options(),
|
||||
@@ -462,21 +434,14 @@ impl<'a> NoteView<'a> {
|
||||
ui.spacing_mut().item_spacing.x = 2.0;
|
||||
|
||||
let note_reply = self
|
||||
.driller
|
||||
.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.driller);
|
||||
|
||||
if action.is_some() {
|
||||
note_action = action;
|
||||
@@ -484,14 +449,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.driller, txn, self.note);
|
||||
ui.add(&mut contents);
|
||||
|
||||
if let Some(action) = contents.action() {
|
||||
@@ -512,8 +470,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.driller.ndb,
|
||||
self.driller.note_cache,
|
||||
self.note.txn().unwrap(),
|
||||
NoteId::new(*self.note.id()),
|
||||
) {
|
||||
|
||||
@@ -14,21 +14,18 @@ use egui::{vec2, Frame, Layout, Margin, Pos2, ScrollArea, Sense, TextBuffer};
|
||||
use enostr::{FilledKeypair, FullKeypair, NoteId, Pubkey, RelayPool};
|
||||
use nostrdb::{Ndb, Transaction};
|
||||
|
||||
use notedeck::{supported_mime_hosted_at_url, Images, NoteCache};
|
||||
use notedeck::supported_mime_hosted_at_url;
|
||||
use tracing::error;
|
||||
|
||||
use super::contents::render_note_preview;
|
||||
use super::contents::{render_note_preview, NoteContentsDriller};
|
||||
|
||||
pub struct PostView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
pub struct PostView<'a, 'd> {
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
draft: &'a mut Draft,
|
||||
post_type: PostType,
|
||||
img_cache: &'a mut Images,
|
||||
note_cache: &'a mut NoteCache,
|
||||
poster: FilledKeypair<'a>,
|
||||
id_source: Option<egui::Id>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -83,29 +80,23 @@ pub struct PostResponse {
|
||||
pub edit_response: egui::Response,
|
||||
}
|
||||
|
||||
impl<'a> PostView<'a> {
|
||||
impl<'a, 'd> PostView<'a, 'd> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
ndb: &'a Ndb,
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
draft: &'a mut Draft,
|
||||
post_type: PostType,
|
||||
img_cache: &'a mut Images,
|
||||
note_cache: &'a mut NoteCache,
|
||||
poster: FilledKeypair<'a>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
) -> Self {
|
||||
let id_source: Option<egui::Id> = None;
|
||||
PostView {
|
||||
ndb,
|
||||
driller,
|
||||
draft,
|
||||
img_cache,
|
||||
note_cache,
|
||||
poster,
|
||||
id_source,
|
||||
post_type,
|
||||
inner_rect,
|
||||
note_options,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,17 +112,21 @@ impl<'a> PostView<'a> {
|
||||
|
||||
// TODO: refactor pfp control to do all of this for us
|
||||
let poster_pfp = self
|
||||
.driller
|
||||
.ndb
|
||||
.get_profile_by_pubkey(txn, self.poster.pubkey.bytes())
|
||||
.as_ref()
|
||||
.ok()
|
||||
.and_then(|p| Some(ui::ProfilePic::from_profile(self.img_cache, p)?.size(pfp_size)));
|
||||
.and_then(|p| {
|
||||
Some(ui::ProfilePic::from_profile(self.driller.img_cache, p)?.size(pfp_size))
|
||||
});
|
||||
|
||||
if let Some(pfp) = poster_pfp {
|
||||
ui.add(pfp);
|
||||
} else {
|
||||
ui.add(
|
||||
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url()).size(pfp_size),
|
||||
ui::ProfilePic::new(self.driller.img_cache, ui::ProfilePic::no_pfp_url())
|
||||
.size(pfp_size),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -228,9 +223,14 @@ impl<'a> PostView<'a> {
|
||||
hint_rect
|
||||
};
|
||||
|
||||
if let Ok(res) = self.ndb.search_profile(txn, mention_str, 10) {
|
||||
let resp = SearchResultsView::new(self.img_cache, self.ndb, txn, &res)
|
||||
.show_in_rect(hint_rect, ui);
|
||||
if let Ok(res) = self.driller.ndb.search_profile(txn, mention_str, 10) {
|
||||
let resp = SearchResultsView::new(
|
||||
self.driller.img_cache,
|
||||
self.driller.ndb,
|
||||
txn,
|
||||
&res,
|
||||
)
|
||||
.show_in_rect(hint_rect, ui);
|
||||
|
||||
match resp {
|
||||
ui::search_results::SearchResultsResponse::SelectResult(
|
||||
@@ -238,7 +238,8 @@ impl<'a> PostView<'a> {
|
||||
) => {
|
||||
if let Some(hint_index) = selection {
|
||||
if let Some(pk) = res.get(hint_index) {
|
||||
let record = self.ndb.get_profile_by_pubkey(txn, pk);
|
||||
let record =
|
||||
self.driller.ndb.get_profile_by_pubkey(txn, pk);
|
||||
|
||||
self.draft.buffer.select_mention_and_replace_name(
|
||||
mention.index,
|
||||
@@ -318,13 +319,10 @@ impl<'a> PostView<'a> {
|
||||
ui.set_max_width(avail_size.x * 0.8);
|
||||
render_note_preview(
|
||||
ui,
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.img_cache,
|
||||
self.driller,
|
||||
txn,
|
||||
id.bytes(),
|
||||
nostrdb::NoteKey::new(0),
|
||||
self.note_options,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -404,11 +402,11 @@ impl<'a> PostView<'a> {
|
||||
};
|
||||
|
||||
if let Some(cache_type) =
|
||||
supported_mime_hosted_at_url(&mut self.img_cache.urls, &media.url)
|
||||
supported_mime_hosted_at_url(&mut self.driller.img_cache.urls, &media.url)
|
||||
{
|
||||
render_images(
|
||||
ui,
|
||||
self.img_cache,
|
||||
self.driller.img_cache,
|
||||
&media.url,
|
||||
crate::images::ImageType::Content(width, height),
|
||||
cache_type,
|
||||
@@ -711,21 +709,25 @@ mod preview {
|
||||
impl App for PostPreview {
|
||||
fn update(&mut self, app: &mut AppContext<'_>, ui: &mut egui::Ui) {
|
||||
let txn = Transaction::new(app.ndb).expect("txn");
|
||||
let mut driller = NoteContentsDriller {
|
||||
ndb: app.ndb,
|
||||
img_cache: app.img_cache,
|
||||
note_cache: app.note_cache,
|
||||
options: NoteOptions::default(),
|
||||
};
|
||||
|
||||
PostView::new(
|
||||
app.ndb,
|
||||
&mut driller,
|
||||
&mut self.draft,
|
||||
PostType::New,
|
||||
app.img_cache,
|
||||
app.note_cache,
|
||||
self.poster.to_filled(),
|
||||
ui.available_rect_before_wrap(),
|
||||
NoteOptions::default(),
|
||||
)
|
||||
.ui(&txn, ui);
|
||||
}
|
||||
}
|
||||
|
||||
impl Preview for PostView<'_> {
|
||||
impl Preview for PostView<'_, '_> {
|
||||
type Prev = PostPreview;
|
||||
|
||||
fn preview(_cfg: PreviewConfig) -> Self::Prev {
|
||||
|
||||
@@ -1,49 +1,38 @@
|
||||
use enostr::{FilledKeypair, NoteId};
|
||||
use nostrdb::Ndb;
|
||||
use notedeck::{Images, NoteCache};
|
||||
|
||||
use crate::{
|
||||
draft::Draft,
|
||||
ui::{self, note::NoteOptions},
|
||||
ui::{self},
|
||||
};
|
||||
|
||||
use super::{PostResponse, PostType};
|
||||
use super::{contents::NoteContentsDriller, PostResponse, PostType};
|
||||
|
||||
pub struct QuoteRepostView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
pub struct QuoteRepostView<'a, 'd> {
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
poster: FilledKeypair<'a>,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut Images,
|
||||
draft: &'a mut Draft,
|
||||
quoting_note: &'a nostrdb::Note<'a>,
|
||||
id_source: Option<egui::Id>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
}
|
||||
|
||||
impl<'a> QuoteRepostView<'a> {
|
||||
impl<'a, 'd> QuoteRepostView<'a, 'd> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
ndb: &'a Ndb,
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
poster: FilledKeypair<'a>,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut Images,
|
||||
draft: &'a mut Draft,
|
||||
quoting_note: &'a nostrdb::Note<'a>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
) -> Self {
|
||||
let id_source: Option<egui::Id> = None;
|
||||
QuoteRepostView {
|
||||
ndb,
|
||||
driller,
|
||||
poster,
|
||||
note_cache,
|
||||
img_cache,
|
||||
draft,
|
||||
quoting_note,
|
||||
id_source,
|
||||
inner_rect,
|
||||
note_options,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +41,11 @@ impl<'a> QuoteRepostView<'a> {
|
||||
let quoting_note_id = self.quoting_note.id();
|
||||
|
||||
ui::PostView::new(
|
||||
self.ndb,
|
||||
self.driller,
|
||||
self.draft,
|
||||
PostType::Quote(NoteId::new(quoting_note_id.to_owned())),
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
self.poster,
|
||||
self.inner_rect,
|
||||
self.note_options,
|
||||
)
|
||||
.id_source(id)
|
||||
.ui(self.quoting_note.txn().unwrap(), ui)
|
||||
|
||||
@@ -1,46 +1,36 @@
|
||||
use crate::draft::Draft;
|
||||
use crate::ui;
|
||||
use crate::ui::note::{NoteOptions, PostResponse, PostType};
|
||||
use crate::ui::note::{PostResponse, PostType};
|
||||
use enostr::{FilledKeypair, NoteId};
|
||||
use nostrdb::Ndb;
|
||||
|
||||
use notedeck::{Images, NoteCache};
|
||||
use super::contents::NoteContentsDriller;
|
||||
|
||||
pub struct PostReplyView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
pub struct PostReplyView<'a, 'd> {
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
poster: FilledKeypair<'a>,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut Images,
|
||||
draft: &'a mut Draft,
|
||||
note: &'a nostrdb::Note<'a>,
|
||||
id_source: Option<egui::Id>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
}
|
||||
|
||||
impl<'a> PostReplyView<'a> {
|
||||
impl<'a, 'd> PostReplyView<'a, 'd> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
ndb: &'a Ndb,
|
||||
driller: &'a mut NoteContentsDriller<'d>,
|
||||
poster: FilledKeypair<'a>,
|
||||
draft: &'a mut Draft,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut Images,
|
||||
note: &'a nostrdb::Note<'a>,
|
||||
inner_rect: egui::Rect,
|
||||
note_options: NoteOptions,
|
||||
) -> Self {
|
||||
let id_source: Option<egui::Id> = None;
|
||||
PostReplyView {
|
||||
ndb,
|
||||
driller,
|
||||
poster,
|
||||
draft,
|
||||
note,
|
||||
note_cache,
|
||||
img_cache,
|
||||
id_source,
|
||||
inner_rect,
|
||||
note_options,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,17 +61,11 @@ impl<'a> PostReplyView<'a> {
|
||||
egui::Frame::none()
|
||||
.outer_margin(egui::Margin::same(note_offset))
|
||||
.show(ui, |ui| {
|
||||
ui::NoteView::new(
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.img_cache,
|
||||
self.note,
|
||||
self.note_options,
|
||||
)
|
||||
.actionbar(false)
|
||||
.medium_pfp(true)
|
||||
.options_button(true)
|
||||
.show(ui);
|
||||
ui::NoteView::new(self.driller, self.note)
|
||||
.actionbar(false)
|
||||
.medium_pfp(true)
|
||||
.options_button(true)
|
||||
.show(ui);
|
||||
});
|
||||
|
||||
let id = self.id();
|
||||
@@ -90,14 +74,11 @@ impl<'a> PostReplyView<'a> {
|
||||
|
||||
let post_response = {
|
||||
ui::PostView::new(
|
||||
self.ndb,
|
||||
self.driller,
|
||||
self.draft,
|
||||
PostType::Reply(NoteId::new(*replying_to)),
|
||||
self.img_cache,
|
||||
self.note_cache,
|
||||
self.poster,
|
||||
self.inner_rect,
|
||||
self.note_options,
|
||||
)
|
||||
.id_source(id)
|
||||
.ui(self.note.txn().unwrap(), ui)
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
use crate::{
|
||||
actionbar::NoteAction,
|
||||
ui::{self, note::NoteOptions},
|
||||
ui::{self},
|
||||
};
|
||||
use egui::{Label, RichText, Sense};
|
||||
use nostrdb::{Ndb, Note, NoteReply, Transaction};
|
||||
use notedeck::{Images, NoteCache};
|
||||
use nostrdb::{Note, NoteReply, Transaction};
|
||||
|
||||
use super::contents::NoteContentsDriller;
|
||||
|
||||
#[must_use = "Please handle the resulting note action"]
|
||||
pub fn reply_desc(
|
||||
ui: &mut egui::Ui,
|
||||
txn: &Transaction,
|
||||
note_reply: &NoteReply,
|
||||
ndb: &Ndb,
|
||||
img_cache: &mut Images,
|
||||
note_cache: &mut NoteCache,
|
||||
note_options: NoteOptions,
|
||||
driller: &mut NoteContentsDriller,
|
||||
) -> Option<NoteAction> {
|
||||
#[cfg(feature = "profiling")]
|
||||
puffin::profile_function!();
|
||||
@@ -27,37 +25,34 @@ pub fn reply_desc(
|
||||
let link_color = visuals.hyperlink_color;
|
||||
|
||||
// note link renderer helper
|
||||
let note_link = |ui: &mut egui::Ui,
|
||||
note_cache: &mut NoteCache,
|
||||
img_cache: &mut Images,
|
||||
text: &str,
|
||||
note: &Note<'_>| {
|
||||
let r = ui.add(
|
||||
Label::new(RichText::new(text).size(size).color(link_color))
|
||||
.sense(Sense::click())
|
||||
.selectable(selectable),
|
||||
);
|
||||
let note_link =
|
||||
|ui: &mut egui::Ui, driller: &mut NoteContentsDriller, text: &str, note: &Note<'_>| {
|
||||
let r = ui.add(
|
||||
Label::new(RichText::new(text).size(size).color(link_color))
|
||||
.sense(Sense::click())
|
||||
.selectable(selectable),
|
||||
);
|
||||
|
||||
if r.clicked() {
|
||||
// TODO: jump to note
|
||||
}
|
||||
if r.clicked() {
|
||||
// TODO: jump to note
|
||||
}
|
||||
|
||||
if r.hovered() {
|
||||
r.on_hover_ui_at_pointer(|ui| {
|
||||
ui.set_max_width(400.0);
|
||||
ui::NoteView::new(ndb, note_cache, img_cache, note, note_options)
|
||||
.actionbar(false)
|
||||
.wide(true)
|
||||
.show(ui);
|
||||
});
|
||||
}
|
||||
};
|
||||
if r.hovered() {
|
||||
r.on_hover_ui_at_pointer(|ui| {
|
||||
ui.set_max_width(400.0);
|
||||
ui::NoteView::new(driller, note)
|
||||
.actionbar(false)
|
||||
.wide(true)
|
||||
.show(ui);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ui.add(Label::new(RichText::new("replying to").size(size).color(color)).selectable(selectable));
|
||||
|
||||
let reply = note_reply.reply()?;
|
||||
|
||||
let reply_note = if let Ok(reply_note) = ndb.get_note_by_id(txn, reply.id) {
|
||||
let reply_note = if let Ok(reply_note) = driller.ndb.get_note_by_id(txn, reply.id) {
|
||||
reply_note
|
||||
} else {
|
||||
ui.add(Label::new(RichText::new("a note").size(size).color(color)).selectable(selectable));
|
||||
@@ -66,7 +61,7 @@ pub fn reply_desc(
|
||||
|
||||
if note_reply.is_reply_to_root() {
|
||||
// We're replying to the root, let's show this
|
||||
let action = ui::Mention::new(ndb, img_cache, txn, reply_note.pubkey())
|
||||
let action = ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
@@ -78,18 +73,19 @@ pub fn reply_desc(
|
||||
|
||||
ui.add(Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable));
|
||||
|
||||
note_link(ui, note_cache, img_cache, "thread", &reply_note);
|
||||
note_link(ui, driller, "thread", &reply_note);
|
||||
} else if let Some(root) = note_reply.root() {
|
||||
// replying to another post in a thread, not the root
|
||||
|
||||
if let Ok(root_note) = ndb.get_note_by_id(txn, root.id) {
|
||||
if let Ok(root_note) = driller.ndb.get_note_by_id(txn, root.id) {
|
||||
if root_note.pubkey() == reply_note.pubkey() {
|
||||
// simply "replying to bob's note" when replying to bob in his thread
|
||||
let action = ui::Mention::new(ndb, img_cache, txn, reply_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
.inner;
|
||||
let action =
|
||||
ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
.inner;
|
||||
|
||||
if action.is_some() {
|
||||
note_action = action;
|
||||
@@ -99,15 +95,16 @@ pub fn reply_desc(
|
||||
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
|
||||
);
|
||||
|
||||
note_link(ui, note_cache, img_cache, "note", &reply_note);
|
||||
note_link(ui, driller, "note", &reply_note);
|
||||
} else {
|
||||
// replying to bob in alice's thread
|
||||
|
||||
let action = ui::Mention::new(ndb, img_cache, txn, reply_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
.inner;
|
||||
let action =
|
||||
ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
.inner;
|
||||
|
||||
if action.is_some() {
|
||||
note_action = action;
|
||||
@@ -117,17 +114,18 @@ pub fn reply_desc(
|
||||
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
|
||||
);
|
||||
|
||||
note_link(ui, note_cache, img_cache, "note", &reply_note);
|
||||
note_link(ui, driller, "note", &reply_note);
|
||||
|
||||
ui.add(
|
||||
Label::new(RichText::new("in").size(size).color(color)).selectable(selectable),
|
||||
);
|
||||
|
||||
let action = ui::Mention::new(ndb, img_cache, txn, root_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
.inner;
|
||||
let action =
|
||||
ui::Mention::new(driller.ndb, driller.img_cache, txn, root_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
.inner;
|
||||
|
||||
if action.is_some() {
|
||||
note_action = action;
|
||||
@@ -137,10 +135,10 @@ pub fn reply_desc(
|
||||
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
|
||||
);
|
||||
|
||||
note_link(ui, note_cache, img_cache, "thread", &root_note);
|
||||
note_link(ui, driller, "thread", &root_note);
|
||||
}
|
||||
} else {
|
||||
let action = ui::Mention::new(ndb, img_cache, txn, reply_note.pubkey())
|
||||
let action = ui::Mention::new(driller.ndb, driller.img_cache, txn, reply_note.pubkey())
|
||||
.size(size)
|
||||
.selectable(selectable)
|
||||
.show(ui)
|
||||
|
||||
Reference in New Issue
Block a user