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

@@ -4,6 +4,7 @@ mod context;
pub use action::{NoteAction, ZapAction, ZapTargetAmount}; pub use action::{NoteAction, ZapAction, ZapTargetAmount};
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection}; pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
use crate::JobPool;
use crate::{notecache::NoteCache, zaps::Zaps, Images}; use crate::{notecache::NoteCache, zaps::Zaps, Images};
use enostr::{NoteId, RelayPool}; use enostr::{NoteId, RelayPool};
use nostrdb::{Ndb, Note, NoteKey, QueryResult, Transaction}; use nostrdb::{Ndb, Note, NoteKey, QueryResult, Transaction};
@@ -19,6 +20,7 @@ pub struct NoteContext<'d> {
pub note_cache: &'d mut NoteCache, pub note_cache: &'d mut NoteCache,
pub zaps: &'d mut Zaps, pub zaps: &'d mut Zaps,
pub pool: &'d mut RelayPool, pub pool: &'d mut RelayPool,
pub job_pool: &'d mut JobPool,
} }
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]

View File

@@ -280,6 +280,7 @@ fn render_nav_body(
note_cache: ctx.note_cache, note_cache: ctx.note_cache,
zaps: ctx.zaps, zaps: ctx.zaps,
pool: ctx.pool, pool: ctx.pool,
job_pool: ctx.job_pool,
}; };
match top { match top {
Route::Timeline(kind) => render_timeline_route( Route::Timeline(kind) => render_timeline_route(
@@ -292,6 +293,7 @@ fn render_nav_body(
depth, depth,
ui, ui,
&mut note_context, &mut note_context,
&mut app.jobs,
), ),
Route::Accounts(amr) => { Route::Accounts(amr) => {
@@ -348,6 +350,7 @@ fn render_nav_body(
&note, &note,
inner_rect, inner_rect,
app.note_options, app.note_options,
&mut app.jobs,
) )
.id_source(id) .id_source(id)
.show(ui) .show(ui)
@@ -384,6 +387,7 @@ fn render_nav_body(
&note, &note,
inner_rect, inner_rect,
app.note_options, app.note_options,
&mut app.jobs,
) )
.id_source(id) .id_source(id)
.show(ui) .show(ui)
@@ -405,6 +409,7 @@ fn render_nav_body(
kp, kp,
inner_rect, inner_rect,
app.note_options, app.note_options,
&mut app.jobs,
) )
.ui(&txn, ui); .ui(&txn, ui);
@@ -424,8 +429,7 @@ fn render_nav_body(
Route::Search => { Route::Search => {
let id = ui.id().with(("search", depth, col)); let id = ui.id().with(("search", depth, col));
let navigating = app let navigating = get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
.columns_mut(ctx.accounts)
.column(col) .column(col)
.router() .router()
.navigating; .navigating;
@@ -448,6 +452,7 @@ fn render_nav_body(
search_buffer, search_buffer,
&mut note_context, &mut note_context,
&ctx.accounts.get_selected_account().map(|a| (&a.key).into()), &ctx.accounts.get_selected_account().map(|a| (&a.key).into()),
&mut app.jobs,
) )
.show(ui, ctx.clipboard) .show(ui, ctx.clipboard)
.map(RenderNavAction::NoteAction) .map(RenderNavAction::NoteAction)

View File

@@ -7,7 +7,7 @@ use crate::{
use enostr::Pubkey; use enostr::Pubkey;
use notedeck::{Accounts, MuteFun, NoteContext, UnknownIds}; use notedeck::{Accounts, MuteFun, NoteContext, UnknownIds};
use notedeck_ui::NoteOptions; use notedeck_ui::{jobs::JobsCache, NoteOptions};
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn render_timeline_route( pub fn render_timeline_route(
@@ -20,6 +20,7 @@ pub fn render_timeline_route(
depth: usize, depth: usize,
ui: &mut egui::Ui, ui: &mut egui::Ui,
note_context: &mut NoteContext, note_context: &mut NoteContext,
jobs: &mut JobsCache,
) -> Option<RenderNavAction> { ) -> Option<RenderNavAction> {
if kind == &TimelineKind::Universe { if kind == &TimelineKind::Universe {
note_options.set_hide_media(true); note_options.set_hide_media(true);
@@ -40,6 +41,7 @@ pub fn render_timeline_route(
note_context, note_context,
note_options, note_options,
&accounts.get_selected_account().map(|a| (&a.key).into()), &accounts.get_selected_account().map(|a| (&a.key).into()),
jobs,
) )
.ui(ui); .ui(ui);
@@ -58,6 +60,7 @@ pub fn render_timeline_route(
&accounts.mutefun(), &accounts.mutefun(),
note_options, note_options,
note_context, note_context,
jobs,
) )
} else { } else {
// we render profiles like timelines if they are at the root // we render profiles like timelines if they are at the root
@@ -68,6 +71,7 @@ pub fn render_timeline_route(
note_context, note_context,
note_options, note_options,
&accounts.get_selected_account().map(|a| (&a.key).into()), &accounts.get_selected_account().map(|a| (&a.key).into()),
jobs,
) )
.ui(ui); .ui(ui);
@@ -88,6 +92,7 @@ pub fn render_timeline_route(
&accounts.mutefun(), &accounts.mutefun(),
note_context, note_context,
&accounts.get_selected_account().map(|a| (&a.key).into()), &accounts.get_selected_account().map(|a| (&a.key).into()),
jobs,
) )
.id_source(egui::Id::new(("threadscroll", col))) .id_source(egui::Id::new(("threadscroll", col)))
.ui(ui) .ui(ui)
@@ -107,6 +112,7 @@ pub fn render_profile_route(
is_muted: &MuteFun, is_muted: &MuteFun,
note_options: NoteOptions, note_options: NoteOptions,
note_context: &mut NoteContext, note_context: &mut NoteContext,
jobs: &mut JobsCache,
) -> Option<RenderNavAction> { ) -> Option<RenderNavAction> {
let action = ProfileView::new( let action = ProfileView::new(
pubkey, pubkey,
@@ -117,6 +123,7 @@ pub fn render_profile_route(
unknown_ids, unknown_ids,
is_muted, is_muted,
note_context, note_context,
jobs,
) )
.ui(ui); .ui(ui);

View File

@@ -14,6 +14,7 @@ use egui::{
}; };
use enostr::{FilledKeypair, FullKeypair, NoteId, Pubkey, RelayPool}; use enostr::{FilledKeypair, FullKeypair, NoteId, Pubkey, RelayPool};
use nostrdb::{Ndb, Transaction}; use nostrdb::{Ndb, Transaction};
use notedeck_ui::jobs::JobsCache;
use notedeck_ui::{ use notedeck_ui::{
gif::{handle_repaint, retrieve_latest_texture}, gif::{handle_repaint, retrieve_latest_texture},
images::render_images, images::render_images,
@@ -32,6 +33,7 @@ pub struct PostView<'a, 'd> {
id_source: Option<egui::Id>, id_source: Option<egui::Id>,
inner_rect: egui::Rect, inner_rect: egui::Rect,
note_options: NoteOptions, note_options: NoteOptions,
jobs: &'a mut JobsCache,
} }
#[derive(Clone)] #[derive(Clone)]
@@ -103,6 +105,7 @@ impl<'a, 'd> PostView<'a, 'd> {
poster: FilledKeypair<'a>, poster: FilledKeypair<'a>,
inner_rect: egui::Rect, inner_rect: egui::Rect,
note_options: NoteOptions, note_options: NoteOptions,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
let id_source: Option<egui::Id> = None; let id_source: Option<egui::Id> = None;
PostView { PostView {
@@ -113,6 +116,7 @@ impl<'a, 'd> PostView<'a, 'd> {
post_type, post_type,
inner_rect, inner_rect,
note_options, note_options,
jobs,
} }
} }
@@ -345,6 +349,7 @@ impl<'a, 'd> PostView<'a, 'd> {
id.bytes(), id.bytes(),
nostrdb::NoteKey::new(0), nostrdb::NoteKey::new(0),
self.note_options, self.note_options,
self.jobs,
) )
}) })
.inner .inner
@@ -696,6 +701,7 @@ mod preview {
pub struct PostPreview { pub struct PostPreview {
draft: Draft, draft: Draft,
poster: FullKeypair, poster: FullKeypair,
jobs: JobsCache,
} }
impl PostPreview { impl PostPreview {
@@ -725,6 +731,7 @@ mod preview {
PostPreview { PostPreview {
draft, draft,
poster: FullKeypair::generate(), poster: FullKeypair::generate(),
jobs: Default::default(),
} }
} }
} }
@@ -738,6 +745,7 @@ mod preview {
note_cache: app.note_cache, note_cache: app.note_cache,
zaps: app.zaps, zaps: app.zaps,
pool: app.pool, pool: app.pool,
job_pool: app.job_pool,
}; };
PostView::new( PostView::new(
@@ -747,6 +755,7 @@ mod preview {
self.poster.to_filled(), self.poster.to_filled(),
ui.available_rect_before_wrap(), ui.available_rect_before_wrap(),
NoteOptions::default(), NoteOptions::default(),
&mut self.jobs,
) )
.ui(&txn, ui); .ui(&txn, ui);

View File

@@ -6,7 +6,7 @@ use crate::{
use enostr::{FilledKeypair, NoteId}; use enostr::{FilledKeypair, NoteId};
use notedeck::NoteContext; use notedeck::NoteContext;
use notedeck_ui::NoteOptions; use notedeck_ui::{jobs::JobsCache, NoteOptions};
pub struct QuoteRepostView<'a, 'd> { pub struct QuoteRepostView<'a, 'd> {
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
@@ -16,6 +16,7 @@ pub struct QuoteRepostView<'a, 'd> {
id_source: Option<egui::Id>, id_source: Option<egui::Id>,
inner_rect: egui::Rect, inner_rect: egui::Rect,
note_options: NoteOptions, note_options: NoteOptions,
jobs: &'a mut JobsCache,
} }
impl<'a, 'd> QuoteRepostView<'a, 'd> { impl<'a, 'd> QuoteRepostView<'a, 'd> {
@@ -27,6 +28,7 @@ impl<'a, 'd> QuoteRepostView<'a, 'd> {
quoting_note: &'a nostrdb::Note<'a>, quoting_note: &'a nostrdb::Note<'a>,
inner_rect: egui::Rect, inner_rect: egui::Rect,
note_options: NoteOptions, note_options: NoteOptions,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
let id_source: Option<egui::Id> = None; let id_source: Option<egui::Id> = None;
QuoteRepostView { QuoteRepostView {
@@ -37,6 +39,7 @@ impl<'a, 'd> QuoteRepostView<'a, 'd> {
id_source, id_source,
inner_rect, inner_rect,
note_options, note_options,
jobs,
} }
} }
@@ -51,6 +54,7 @@ impl<'a, 'd> QuoteRepostView<'a, 'd> {
self.poster, self.poster,
self.inner_rect, self.inner_rect,
self.note_options, self.note_options,
self.jobs,
) )
.id_source(id) .id_source(id)
.ui(self.quoting_note.txn().unwrap(), ui); .ui(self.quoting_note.txn().unwrap(), ui);

View File

@@ -6,6 +6,7 @@ use crate::ui::{
use enostr::{FilledKeypair, NoteId}; use enostr::{FilledKeypair, NoteId};
use notedeck::NoteContext; use notedeck::NoteContext;
use notedeck_ui::jobs::JobsCache;
use notedeck_ui::{NoteOptions, NoteView, ProfilePic}; use notedeck_ui::{NoteOptions, NoteView, ProfilePic};
pub struct PostReplyView<'a, 'd> { pub struct PostReplyView<'a, 'd> {
@@ -16,6 +17,7 @@ pub struct PostReplyView<'a, 'd> {
id_source: Option<egui::Id>, id_source: Option<egui::Id>,
inner_rect: egui::Rect, inner_rect: egui::Rect,
note_options: NoteOptions, note_options: NoteOptions,
jobs: &'a mut JobsCache,
} }
impl<'a, 'd> PostReplyView<'a, 'd> { impl<'a, 'd> PostReplyView<'a, 'd> {
@@ -27,6 +29,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
note: &'a nostrdb::Note<'a>, note: &'a nostrdb::Note<'a>,
inner_rect: egui::Rect, inner_rect: egui::Rect,
note_options: NoteOptions, note_options: NoteOptions,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
let id_source: Option<egui::Id> = None; let id_source: Option<egui::Id> = None;
PostReplyView { PostReplyView {
@@ -37,6 +40,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
id_source, id_source,
inner_rect, inner_rect,
note_options, note_options,
jobs,
} }
} }
@@ -71,6 +75,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
&Some(self.poster.into()), &Some(self.poster.into()),
self.note, self.note,
self.note_options, self.note_options,
self.jobs,
) )
.truncate(false) .truncate(false)
.selectable_text(true) .selectable_text(true)
@@ -93,6 +98,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
self.poster, self.poster,
self.inner_rect, self.inner_rect,
self.note_options, self.note_options,
self.jobs,
) )
.id_source(id) .id_source(id)
.ui(self.note.txn().unwrap(), ui) .ui(self.note.txn().unwrap(), ui)

View File

@@ -15,6 +15,7 @@ use notedeck::{
NotedeckTextStyle, UnknownIds, NotedeckTextStyle, UnknownIds,
}; };
use notedeck_ui::{ use notedeck_ui::{
jobs::JobsCache,
profile::{about_section_widget, banner, display_name_widget}, profile::{about_section_widget, banner, display_name_widget},
NoteOptions, ProfilePic, NoteOptions, ProfilePic,
}; };
@@ -28,6 +29,7 @@ pub struct ProfileView<'a, 'd> {
unknown_ids: &'a mut UnknownIds, unknown_ids: &'a mut UnknownIds,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
jobs: &'a mut JobsCache,
} }
pub enum ProfileViewAction { pub enum ProfileViewAction {
@@ -46,6 +48,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
unknown_ids: &'a mut UnknownIds, unknown_ids: &'a mut UnknownIds,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
ProfileView { ProfileView {
pubkey, pubkey,
@@ -56,6 +59,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
unknown_ids, unknown_ids,
is_muted, is_muted,
note_context, note_context,
jobs,
} }
} }
@@ -112,6 +116,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
.accounts .accounts
.get_selected_account() .get_selected_account()
.map(|a| (&a.key).into()), .map(|a| (&a.key).into()),
self.jobs,
) )
.show(ui) .show(ui)
{ {

View File

@@ -5,7 +5,7 @@ use crate::ui::timeline::TimelineTabView;
use egui_winit::clipboard::Clipboard; use egui_winit::clipboard::Clipboard;
use nostrdb::{Filter, Transaction}; use nostrdb::{Filter, Transaction};
use notedeck::{MuteFun, NoteAction, NoteContext, NoteRef}; use notedeck::{MuteFun, NoteAction, NoteContext, NoteRef};
use notedeck_ui::{icons::search_icon, padding, NoteOptions}; use notedeck_ui::{icons::search_icon, jobs::JobsCache, padding, NoteOptions};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use tracing::{error, info, warn}; use tracing::{error, info, warn};
@@ -20,6 +20,7 @@ pub struct SearchView<'a, 'd> {
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
} }
impl<'a, 'd> SearchView<'a, 'd> { impl<'a, 'd> SearchView<'a, 'd> {
@@ -30,6 +31,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
query: &'a mut SearchQueryState, query: &'a mut SearchQueryState,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
Self { Self {
txn, txn,
@@ -38,6 +40,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
note_options, note_options,
note_context, note_context,
cur_acc, cur_acc,
jobs,
} }
} }
@@ -81,6 +84,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
self.is_muted, self.is_muted,
self.note_context, self.note_context,
self.cur_acc, self.cur_acc,
self.jobs,
) )
.show(ui) .show(ui)
}) })

View File

@@ -1,6 +1,7 @@
use enostr::KeypairUnowned; use enostr::KeypairUnowned;
use nostrdb::Transaction; use nostrdb::Transaction;
use notedeck::{MuteFun, NoteAction, NoteContext, RootNoteId, UnknownIds}; use notedeck::{MuteFun, NoteAction, NoteContext, RootNoteId, UnknownIds};
use notedeck_ui::jobs::JobsCache;
use notedeck_ui::NoteOptions; use notedeck_ui::NoteOptions;
use tracing::error; use tracing::error;
@@ -16,6 +17,7 @@ pub struct ThreadView<'a, 'd> {
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
} }
impl<'a, 'd> ThreadView<'a, 'd> { impl<'a, 'd> ThreadView<'a, 'd> {
@@ -28,6 +30,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
let id_source = egui::Id::new("threadscroll_threadview"); let id_source = egui::Id::new("threadscroll_threadview");
ThreadView { ThreadView {
@@ -39,6 +42,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
is_muted, is_muted,
note_context, note_context,
cur_acc, cur_acc,
jobs,
} }
} }
@@ -102,6 +106,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
self.is_muted, self.is_muted,
self.note_context, self.note_context,
self.cur_acc, self.cur_acc,
self.jobs,
) )
.show(ui) .show(ui)
}) })

View File

@@ -3,6 +3,7 @@ use egui::{vec2, Direction, Layout, Pos2, Stroke};
use egui_tabs::TabColor; use egui_tabs::TabColor;
use enostr::KeypairUnowned; use enostr::KeypairUnowned;
use nostrdb::Transaction; use nostrdb::Transaction;
use notedeck_ui::jobs::JobsCache;
use std::f32::consts::PI; use std::f32::consts::PI;
use tracing::{error, warn}; use tracing::{error, warn};
@@ -21,6 +22,7 @@ pub struct TimelineView<'a, 'd> {
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
} }
impl<'a, 'd> TimelineView<'a, 'd> { impl<'a, 'd> TimelineView<'a, 'd> {
@@ -32,6 +34,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
note_options: NoteOptions, note_options: NoteOptions,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
let reverse = false; let reverse = false;
TimelineView { TimelineView {
@@ -42,6 +45,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
is_muted, is_muted,
note_context, note_context,
cur_acc, cur_acc,
jobs,
} }
} }
@@ -55,6 +59,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
self.is_muted, self.is_muted,
self.note_context, self.note_context,
self.cur_acc, self.cur_acc,
self.jobs,
) )
} }
@@ -74,6 +79,7 @@ fn timeline_ui(
is_muted: &MuteFun, is_muted: &MuteFun,
note_context: &mut NoteContext, note_context: &mut NoteContext,
cur_acc: &Option<KeypairUnowned>, cur_acc: &Option<KeypairUnowned>,
jobs: &mut JobsCache,
) -> Option<NoteAction> { ) -> Option<NoteAction> {
//padding(4.0, ui, |ui| ui.heading("Notifications")); //padding(4.0, ui, |ui| ui.heading("Notifications"));
/* /*
@@ -152,6 +158,7 @@ fn timeline_ui(
is_muted, is_muted,
note_context, note_context,
cur_acc, cur_acc,
jobs,
) )
.show(ui) .show(ui)
}); });
@@ -323,6 +330,7 @@ pub struct TimelineTabView<'a, 'd> {
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
} }
impl<'a, 'd> TimelineTabView<'a, 'd> { impl<'a, 'd> TimelineTabView<'a, 'd> {
@@ -335,6 +343,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>, cur_acc: &'a Option<KeypairUnowned<'a>>,
jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
Self { Self {
tab, tab,
@@ -344,6 +353,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
is_muted, is_muted,
note_context, note_context,
cur_acc, cur_acc,
jobs,
} }
} }
@@ -395,6 +405,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
self.cur_acc, self.cur_acc,
&note, &note,
self.note_options, self.note_options,
self.jobs,
) )
.show(ui); .show(ui);

View File

@@ -9,6 +9,7 @@ use enostr::KeypairUnowned;
use futures::StreamExt; use futures::StreamExt;
use nostrdb::Transaction; use nostrdb::Transaction;
use notedeck::{AppAction, AppContext}; use notedeck::{AppAction, AppContext};
use notedeck_ui::jobs::JobsCache;
use std::collections::HashMap; use std::collections::HashMap;
use std::string::ToString; use std::string::ToString;
use std::sync::mpsc::{self, Receiver}; use std::sync::mpsc::{self, Receiver};
@@ -42,6 +43,7 @@ pub struct Dave {
client: async_openai::Client<OpenAIConfig>, client: async_openai::Client<OpenAIConfig>,
incoming_tokens: Option<Receiver<DaveApiResponse>>, incoming_tokens: Option<Receiver<DaveApiResponse>>,
model_config: ModelConfig, model_config: ModelConfig,
jobs: JobsCache,
} }
/// Calculate an anonymous user_id from a keypair /// Calculate an anonymous user_id from a keypair
@@ -106,6 +108,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
input, input,
model_config, model_config,
chat: vec![], chat: vec![],
jobs: JobsCache::default(),
} }
} }
@@ -177,7 +180,11 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
} }
fn ui(&mut self, app_ctx: &mut AppContext, ui: &mut egui::Ui) -> DaveResponse { fn ui(&mut self, app_ctx: &mut AppContext, ui: &mut egui::Ui) -> DaveResponse {
DaveUi::new(self.model_config.trial, &self.chat, &mut self.input).ui(app_ctx, ui) DaveUi::new(self.model_config.trial, &self.chat, &mut self.input).ui(
app_ctx,
&mut self.jobs,
ui,
)
} }
fn handle_new_chat(&mut self) { fn handle_new_chat(&mut self) {

View File

@@ -5,7 +5,7 @@ use crate::{
use egui::{Align, Key, KeyboardShortcut, Layout, Modifiers}; use egui::{Align, Key, KeyboardShortcut, Layout, Modifiers};
use nostrdb::{Ndb, Transaction}; use nostrdb::{Ndb, Transaction};
use notedeck::{AppContext, NoteAction, NoteContext}; use notedeck::{AppContext, NoteAction, NoteContext};
use notedeck_ui::{icons::search_icon, NoteOptions, ProfilePic}; use notedeck_ui::{icons::search_icon, jobs::JobsCache, NoteOptions, ProfilePic};
/// DaveUi holds all of the data it needs to render itself /// DaveUi holds all of the data it needs to render itself
pub struct DaveUi<'a> { pub struct DaveUi<'a> {
@@ -83,7 +83,12 @@ impl<'a> DaveUi<'a> {
} }
/// The main render function. Call this to render Dave /// The main render function. Call this to render Dave
pub fn ui(&mut self, app_ctx: &mut AppContext, ui: &mut egui::Ui) -> DaveResponse { pub fn ui(
&mut self,
app_ctx: &mut AppContext,
jobs: &mut JobsCache,
ui: &mut egui::Ui,
) -> DaveResponse {
let mut action: Option<DaveAction> = None; let mut action: Option<DaveAction> = None;
// Scroll area for chat messages // Scroll area for chat messages
let new_resp = { let new_resp = {
@@ -124,7 +129,7 @@ impl<'a> DaveUi<'a> {
.show(ui, |ui| { .show(ui, |ui| {
Self::chat_frame(ui.ctx()) Self::chat_frame(ui.ctx())
.show(ui, |ui| { .show(ui, |ui| {
ui.vertical(|ui| self.render_chat(app_ctx, ui)).inner ui.vertical(|ui| self.render_chat(app_ctx, jobs, ui)).inner
}) })
.inner .inner
}) })
@@ -158,7 +163,12 @@ impl<'a> DaveUi<'a> {
} }
/// Render a chat message (user, assistant, tool call/response, etc) /// Render a chat message (user, assistant, tool call/response, etc)
fn render_chat(&self, ctx: &mut AppContext, ui: &mut egui::Ui) -> Option<NoteAction> { fn render_chat(
&self,
ctx: &mut AppContext,
jobs: &mut JobsCache,
ui: &mut egui::Ui,
) -> Option<NoteAction> {
let mut action: Option<NoteAction> = None; let mut action: Option<NoteAction> = None;
for message in self.chat { for message in self.chat {
let r = match message { let r = match message {
@@ -183,7 +193,7 @@ impl<'a> DaveUi<'a> {
// have a debug option to show this // have a debug option to show this
None None
} }
Message::ToolCalls(toolcalls) => Self::tool_calls_ui(ctx, toolcalls, ui), Message::ToolCalls(toolcalls) => Self::tool_calls_ui(ctx, jobs, toolcalls, ui),
}; };
if r.is_some() { if r.is_some() {
@@ -208,6 +218,7 @@ impl<'a> DaveUi<'a> {
/// The ai has asked us to render some notes, so we do that here /// The ai has asked us to render some notes, so we do that here
fn present_notes_ui( fn present_notes_ui(
ctx: &mut AppContext, ctx: &mut AppContext,
jobs: &mut JobsCache,
call: &PresentNotesCall, call: &PresentNotesCall,
ui: &mut egui::Ui, ui: &mut egui::Ui,
) -> Option<NoteAction> { ) -> Option<NoteAction> {
@@ -217,6 +228,7 @@ impl<'a> DaveUi<'a> {
note_cache: ctx.note_cache, note_cache: ctx.note_cache,
zaps: ctx.zaps, zaps: ctx.zaps,
pool: ctx.pool, pool: ctx.pool,
job_pool: ctx.job_pool,
}; };
let txn = Transaction::new(note_context.ndb).unwrap(); let txn = Transaction::new(note_context.ndb).unwrap();
@@ -244,6 +256,7 @@ impl<'a> DaveUi<'a> {
&None, &None,
&note, &note,
NoteOptions::default(), NoteOptions::default(),
jobs,
) )
.preview_style() .preview_style()
.hide_media(true) .hide_media(true)
@@ -266,6 +279,7 @@ impl<'a> DaveUi<'a> {
fn tool_calls_ui( fn tool_calls_ui(
ctx: &mut AppContext, ctx: &mut AppContext,
jobs: &mut JobsCache,
toolcalls: &[ToolCall], toolcalls: &[ToolCall],
ui: &mut egui::Ui, ui: &mut egui::Ui,
) -> Option<NoteAction> { ) -> Option<NoteAction> {
@@ -275,7 +289,7 @@ impl<'a> DaveUi<'a> {
for call in toolcalls { for call in toolcalls {
match call.calls() { match call.calls() {
ToolCalls::PresentNotes(call) => { ToolCalls::PresentNotes(call) => {
let r = Self::present_notes_ui(ctx, call, ui); let r = Self::present_notes_ui(ctx, jobs, call, ui);
if r.is_some() { if r.is_some() {
note_action = r; note_action = r;
} }

View File

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

View File

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

View File

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