propagate JobsCache

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-04-18 22:48:57 -05:00
parent e6212e5d17
commit a29277d263
15 changed files with 153 additions and 42 deletions

View File

@@ -1,6 +1,7 @@
use crate::{
gif::{handle_repaint, retrieve_latest_texture},
images::{render_images, ImageType},
jobs::JobsCache,
note::{NoteAction, NoteOptions, NoteResponse, NoteView},
};
@@ -18,6 +19,7 @@ pub struct NoteContents<'a, 'd> {
note: &'a Note<'a>,
options: NoteOptions,
pub action: Option<NoteAction>,
jobs: &'a mut JobsCache,
}
impl<'a, 'd> NoteContents<'a, 'd> {
@@ -28,6 +30,7 @@ impl<'a, 'd> NoteContents<'a, 'd> {
txn: &'a Transaction,
note: &'a Note,
options: NoteOptions,
jobs: &'a mut JobsCache,
) -> Self {
NoteContents {
note_context,
@@ -36,6 +39,7 @@ impl<'a, 'd> NoteContents<'a, 'd> {
note,
options,
action: None,
jobs,
}
}
}
@@ -49,6 +53,7 @@ impl egui::Widget for &mut NoteContents<'_, '_> {
self.txn,
self.note,
self.options,
self.jobs,
);
self.action = result.action;
result.response
@@ -67,6 +72,7 @@ pub fn render_note_preview(
id: &[u8; 32],
parent: NoteKey,
note_options: NoteOptions,
jobs: &mut JobsCache,
) -> NoteResponse {
let note = if let Ok(note) = note_context.ndb.get_note_by_id(txn, id) {
// TODO: support other preview kinds
@@ -91,7 +97,7 @@ pub fn render_note_preview(
*/
};
NoteView::new(note_context, cur_acc, &note, note_options)
NoteView::new(note_context, cur_acc, &note, note_options, jobs)
.preview_style()
.parent(parent)
.show(ui)
@@ -106,6 +112,7 @@ pub fn render_note_contents(
txn: &Transaction,
note: &Note,
options: NoteOptions,
jobs: &mut JobsCache,
) -> NoteResponse {
let note_key = note.key().expect("todo: implement non-db notes");
let selectable = options.has_selectable_text();
@@ -254,7 +261,7 @@ pub fn render_note_contents(
});
let preview_note_action = if let Some((id, _block_str)) = inline_note {
render_note_preview(ui, note_context, cur_acc, txn, id, note_key, options).action
render_note_preview(ui, note_context, cur_acc, txn, id, note_key, options, jobs).action
} else {
None
};

View File

@@ -3,6 +3,7 @@ pub mod context;
pub mod options;
pub mod reply_description;
use crate::jobs::JobsCache;
use crate::{
profile::name::one_line_display_name_widget, widgets::x_button, ImagePulseTint, ProfilePic,
ProfilePreview, Username,
@@ -32,6 +33,7 @@ pub struct NoteView<'a, 'd> {
note: &'a nostrdb::Note<'a>,
framed: bool,
flags: NoteOptions,
jobs: &'a mut JobsCache,
}
pub struct NoteResponse {
@@ -73,6 +75,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
cur_acc: &'a Option<KeypairUnowned<'a>>,
note: &'a nostrdb::Note<'a>,
mut flags: NoteOptions,
jobs: &'a mut JobsCache,
) -> Self {
flags.set_actionbar(true);
flags.set_note_previews(true);
@@ -87,6 +90,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
note,
flags,
framed,
jobs,
}
}
@@ -212,6 +216,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
txn,
self.note,
self.flags,
self.jobs,
));
//});
})
@@ -326,7 +331,14 @@ impl<'a, 'd> NoteView<'a, 'd> {
.text_style(style.text_style()),
);
});
NoteView::new(self.note_context, self.cur_acc, &note_to_repost, self.flags).show(ui)
NoteView::new(
self.note_context,
self.cur_acc,
&note_to_repost,
self.flags,
self.jobs,
)
.show(ui)
} else {
self.show_standard(ui)
}
@@ -426,6 +438,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
&note_reply,
self.note_context,
self.flags,
self.jobs,
)
})
.inner;
@@ -437,8 +450,14 @@ impl<'a, 'd> NoteView<'a, 'd> {
});
});
let mut contents =
NoteContents::new(self.note_context, self.cur_acc, txn, self.note, self.flags);
let mut contents = NoteContents::new(
self.note_context,
self.cur_acc,
txn,
self.note,
self.flags,
self.jobs,
);
ui.add(&mut contents);
@@ -489,6 +508,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
&note_reply,
self.note_context,
self.flags,
self.jobs,
);
if action.is_some() {
@@ -503,6 +523,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
txn,
self.note,
self.flags,
self.jobs,
);
ui.add(&mut contents);

View File

@@ -2,7 +2,7 @@ use egui::{Label, RichText, Sense};
use nostrdb::{Note, NoteReply, Transaction};
use super::NoteOptions;
use crate::{note::NoteView, Mention};
use crate::{jobs::JobsCache, note::NoteView, Mention};
use enostr::KeypairUnowned;
use notedeck::{NoteAction, NoteContext};
@@ -15,6 +15,7 @@ pub fn reply_desc(
note_reply: &NoteReply,
note_context: &mut NoteContext,
note_options: NoteOptions,
jobs: &mut JobsCache,
) -> Option<NoteAction> {
let mut note_action: Option<NoteAction> = None;
let size = 10.0;
@@ -24,28 +25,31 @@ pub fn reply_desc(
let link_color = visuals.hyperlink_color;
// note link renderer helper
let note_link =
|ui: &mut egui::Ui, note_context: &mut NoteContext, 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,
note_context: &mut NoteContext,
text: &str,
note: &Note<'_>,
jobs: &mut JobsCache| {
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);
NoteView::new(note_context, cur_acc, 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);
NoteView::new(note_context, cur_acc, note, note_options, jobs)
.actionbar(false)
.wide(true)
.show(ui);
});
}
};
ui.add(Label::new(RichText::new("replying to").size(size).color(color)).selectable(selectable));
@@ -77,7 +81,7 @@ pub fn reply_desc(
ui.add(Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable));
note_link(ui, note_context, "thread", &reply_note);
note_link(ui, note_context, "thread", &reply_note, jobs);
} else if let Some(root) = note_reply.root() {
// replying to another post in a thread, not the root
@@ -103,7 +107,7 @@ pub fn reply_desc(
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
);
note_link(ui, note_context, "note", &reply_note);
note_link(ui, note_context, "note", &reply_note, jobs);
} else {
// replying to bob in alice's thread
@@ -126,7 +130,7 @@ pub fn reply_desc(
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
);
note_link(ui, note_context, "note", &reply_note);
note_link(ui, note_context, "note", &reply_note, jobs);
ui.add(
Label::new(RichText::new("in").size(size).color(color)).selectable(selectable),
@@ -151,7 +155,7 @@ pub fn reply_desc(
Label::new(RichText::new("'s").size(size).color(color)).selectable(selectable),
);
note_link(ui, note_context, "thread", &root_note);
note_link(ui, note_context, "thread", &root_note, jobs);
}
} else {
let action = Mention::new(