propagate current account

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-04-08 17:48:07 -04:00
parent 18ea05db0a
commit 5917bc16fd
13 changed files with 120 additions and 20 deletions

View File

@@ -16,6 +16,20 @@ pub struct Keypair {
pub secret_key: Option<SecretKey>, pub secret_key: Option<SecretKey>,
} }
pub struct KeypairUnowned<'a> {
pub pubkey: &'a Pubkey,
pub secret_key: Option<&'a SecretKey>,
}
impl<'a> From<&'a Keypair> for KeypairUnowned<'a> {
fn from(value: &'a Keypair) -> Self {
Self {
pubkey: &value.pubkey,
secret_key: value.secret_key.as_ref(),
}
}
}
impl Keypair { impl Keypair {
pub fn from_secret(secret_key: SecretKey) -> Self { pub fn from_secret(secret_key: SecretKey) -> Self {
let cloned_secret_key = secret_key.clone(); let cloned_secret_key = secret_key.clone();
@@ -70,6 +84,15 @@ impl<'a> FilledKeypair<'a> {
} }
} }
impl<'a> From<FilledKeypair<'a>> for KeypairUnowned<'a> {
fn from(value: FilledKeypair<'a>) -> Self {
Self {
pubkey: value.pubkey,
secret_key: Some(value.secret_key),
}
}
}
impl FullKeypair { impl FullKeypair {
pub fn new(pubkey: Pubkey, secret_key: SecretKey) -> Self { pub fn new(pubkey: Pubkey, secret_key: SecretKey) -> Self {
FullKeypair { pubkey, secret_key } FullKeypair { pubkey, secret_key }

View File

@@ -11,7 +11,7 @@ pub use client::{ClientMessage, EventClientMessage};
pub use error::Error; pub use error::Error;
pub use ewebsock; pub use ewebsock;
pub use filter::Filter; pub use filter::Filter;
pub use keypair::{FilledKeypair, FullKeypair, Keypair, SerializableKeypair}; pub use keypair::{FilledKeypair, FullKeypair, Keypair, KeypairUnowned, SerializableKeypair};
pub use nostr::SecretKey; pub use nostr::SecretKey;
pub use note::{Note, NoteId}; pub use note::{Note, NoteId};
pub use profile::Profile; pub use profile::Profile;

View File

@@ -432,6 +432,7 @@ fn render_nav_body(
app.note_options, app.note_options,
search_buffer, search_buffer,
&mut note_context, &mut note_context,
&ctx.accounts.get_selected_account().map(|a| (&a.key).into()),
) )
.show(ui, ctx.clipboard) .show(ui, ctx.clipboard)
.map(RenderNavAction::NoteAction) .map(RenderNavAction::NoteAction)

View File

@@ -42,6 +42,7 @@ pub fn render_timeline_route(
&accounts.mutefun(), &accounts.mutefun(),
note_context, note_context,
note_options, note_options,
&accounts.get_selected_account().map(|a| (&a.key).into()),
) )
.ui(ui); .ui(ui);
@@ -69,6 +70,7 @@ pub fn render_timeline_route(
&accounts.mutefun(), &accounts.mutefun(),
note_context, note_context,
note_options, note_options,
&accounts.get_selected_account().map(|a| (&a.key).into()),
) )
.ui(ui); .ui(ui);
@@ -83,6 +85,7 @@ pub fn render_timeline_route(
note_options, note_options,
&accounts.mutefun(), &accounts.mutefun(),
note_context, note_context,
&accounts.get_selected_account().map(|a| (&a.key).into()),
) )
.id_source(egui::Id::new(("threadscroll", col))) .id_source(egui::Id::new(("threadscroll", col)))
.ui(ui) .ui(ui)

View File

@@ -6,6 +6,7 @@ use crate::ui::{
}; };
use crate::{actionbar::NoteAction, images::ImageType, timeline::TimelineKind}; use crate::{actionbar::NoteAction, images::ImageType, timeline::TimelineKind};
use egui::{Button, Color32, Hyperlink, Image, Response, RichText, Sense, Window}; use egui::{Button, Color32, Hyperlink, Image, Response, RichText, Sense, Window};
use enostr::KeypairUnowned;
use nostrdb::{BlockType, Mention, Ndb, Note, NoteKey, Transaction}; use nostrdb::{BlockType, Mention, Ndb, Note, NoteKey, Transaction};
use tracing::warn; use tracing::warn;
@@ -22,6 +23,7 @@ pub struct NoteContext<'d> {
pub struct NoteContents<'a, 'd> { pub struct NoteContents<'a, 'd> {
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
txn: &'a Transaction, txn: &'a Transaction,
note: &'a Note<'a>, note: &'a Note<'a>,
options: NoteOptions, options: NoteOptions,
@@ -32,12 +34,14 @@ impl<'a, 'd> NoteContents<'a, 'd> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
txn: &'a Transaction, txn: &'a Transaction,
note: &'a Note, note: &'a Note,
options: ui::note::NoteOptions, options: ui::note::NoteOptions,
) -> Self { ) -> Self {
NoteContents { NoteContents {
note_context, note_context,
cur_acc,
txn, txn,
note, note,
options, options,
@@ -52,7 +56,14 @@ impl<'a, 'd> NoteContents<'a, 'd> {
impl egui::Widget for &mut NoteContents<'_, '_> { impl egui::Widget for &mut NoteContents<'_, '_> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response { fn ui(self, ui: &mut egui::Ui) -> egui::Response {
let result = render_note_contents(ui, self.note_context, self.txn, self.note, self.options); let result = render_note_contents(
ui,
self.note_context,
self.cur_acc,
self.txn,
self.note,
self.options,
);
self.action = result.action; self.action = result.action;
result.response result.response
} }
@@ -65,6 +76,7 @@ impl egui::Widget for &mut NoteContents<'_, '_> {
pub fn render_note_preview( pub fn render_note_preview(
ui: &mut egui::Ui, ui: &mut egui::Ui,
note_context: &mut NoteContext, note_context: &mut NoteContext,
cur_acc: &Option<KeypairUnowned>,
txn: &Transaction, txn: &Transaction,
id: &[u8; 32], id: &[u8; 32],
parent: NoteKey, parent: NoteKey,
@@ -103,7 +115,7 @@ pub fn render_note_preview(
ui.visuals().noninteractive().bg_stroke.color, ui.visuals().noninteractive().bg_stroke.color,
)) ))
.show(ui, |ui| { .show(ui, |ui| {
ui::NoteView::new(note_context, &note, note_options) ui::NoteView::new(note_context, cur_acc, &note, note_options)
.actionbar(false) .actionbar(false)
.small_pfp(true) .small_pfp(true)
.wide(true) .wide(true)
@@ -121,6 +133,7 @@ pub fn render_note_preview(
fn render_note_contents( fn render_note_contents(
ui: &mut egui::Ui, ui: &mut egui::Ui,
note_context: &mut NoteContext, note_context: &mut NoteContext,
cur_acc: &Option<KeypairUnowned>,
txn: &Transaction, txn: &Transaction,
note: &Note, note: &Note,
options: NoteOptions, options: NoteOptions,
@@ -241,7 +254,7 @@ 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, txn, id, note_key, options).action render_note_preview(ui, note_context, cur_acc, txn, id, note_key, options).action
} else { } else {
None None
}; };

View File

@@ -24,7 +24,7 @@ use crate::{
use egui::emath::{pos2, Vec2}; use egui::emath::{pos2, Vec2};
use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense}; use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense};
use enostr::{NoteId, Pubkey}; use enostr::{KeypairUnowned, NoteId, Pubkey};
use nostrdb::{Ndb, Note, NoteKey, Transaction}; use nostrdb::{Ndb, Note, NoteKey, Transaction};
use notedeck::{CachedNote, NoteCache, NotedeckTextStyle}; use notedeck::{CachedNote, NoteCache, NotedeckTextStyle};
@@ -32,6 +32,7 @@ use super::profile::preview::one_line_display_name_widget;
pub struct NoteView<'a, 'd> { pub struct NoteView<'a, 'd> {
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
parent: Option<NoteKey>, parent: Option<NoteKey>,
note: &'a nostrdb::Note<'a>, note: &'a nostrdb::Note<'a>,
flags: NoteOptions, flags: NoteOptions,
@@ -72,6 +73,7 @@ impl View for NoteView<'_, '_> {
impl<'a, 'd> NoteView<'a, 'd> { impl<'a, 'd> NoteView<'a, 'd> {
pub fn new( pub fn new(
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
cur_acc: &'a Option<KeypairUnowned<'a>>,
note: &'a nostrdb::Note<'a>, note: &'a nostrdb::Note<'a>,
mut flags: NoteOptions, mut flags: NoteOptions,
) -> Self { ) -> Self {
@@ -81,6 +83,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
let parent: Option<NoteKey> = None; let parent: Option<NoteKey> = None;
Self { Self {
note_context, note_context,
cur_acc,
parent, parent,
note, note,
flags, flags,
@@ -180,6 +183,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
ui.add(&mut NoteContents::new( ui.add(&mut NoteContents::new(
self.note_context, self.note_context,
self.cur_acc,
txn, txn,
self.note, self.note,
self.flags, self.flags,
@@ -300,7 +304,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
.text_style(style.text_style()), .text_style(style.text_style()),
); );
}); });
NoteView::new(self.note_context, &note_to_repost, self.flags).show(ui) NoteView::new(self.note_context, self.cur_acc, &note_to_repost, self.flags).show(ui)
} else { } else {
self.show_standard(ui) self.show_standard(ui)
} }
@@ -377,7 +381,14 @@ impl<'a, 'd> NoteView<'a, 'd> {
if note_reply.reply().is_some() { if note_reply.reply().is_some() {
let action = ui let action = ui
.horizontal(|ui| { .horizontal(|ui| {
reply_desc(ui, txn, &note_reply, self.note_context, self.flags) reply_desc(
ui,
self.cur_acc,
txn,
&note_reply,
self.note_context,
self.flags,
)
}) })
.inner; .inner;
@@ -388,7 +399,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
}); });
}); });
let mut contents = NoteContents::new(self.note_context, txn, self.note, self.flags); let mut contents =
NoteContents::new(self.note_context, self.cur_acc, txn, self.note, self.flags);
ui.add(&mut contents); ui.add(&mut contents);
@@ -426,8 +438,14 @@ impl<'a, 'd> NoteView<'a, 'd> {
.borrow(self.note.tags()); .borrow(self.note.tags());
if note_reply.reply().is_some() { if note_reply.reply().is_some() {
let action = let action = reply_desc(
reply_desc(ui, txn, &note_reply, self.note_context, self.flags); ui,
self.cur_acc,
txn,
&note_reply,
self.note_context,
self.flags,
);
if action.is_some() { if action.is_some() {
note_action = action; note_action = action;
@@ -435,8 +453,13 @@ impl<'a, 'd> NoteView<'a, 'd> {
} }
}); });
let mut contents = let mut contents = NoteContents::new(
NoteContents::new(self.note_context, txn, self.note, self.flags); self.note_context,
self.cur_acc,
txn,
self.note,
self.flags,
);
ui.add(&mut contents); ui.add(&mut contents);
if let Some(action) = contents.action() { if let Some(action) = contents.action() {

View File

@@ -331,6 +331,7 @@ impl<'a, 'd> PostView<'a, 'd> {
let resp = render_note_preview( let resp = render_note_preview(
ui, ui,
self.note_context, self.note_context,
&Some(self.poster.into()),
txn, txn,
id.bytes(), id.bytes(),
nostrdb::NoteKey::new(0), nostrdb::NoteKey::new(0),

View File

@@ -64,7 +64,12 @@ impl<'a, 'd> PostReplyView<'a, 'd> {
let selection = egui::Frame::NONE let selection = egui::Frame::NONE
.outer_margin(egui::Margin::same(note_offset)) .outer_margin(egui::Margin::same(note_offset))
.show(ui, |ui| { .show(ui, |ui| {
ui::NoteView::new(self.note_context, self.note, self.note_options) ui::NoteView::new(
self.note_context,
&Some(self.poster.into()),
self.note,
self.note_options,
)
.actionbar(false) .actionbar(false)
.medium_pfp(true) .medium_pfp(true)
.options_button(true) .options_button(true)

View File

@@ -3,6 +3,7 @@ use crate::{
ui::{self}, ui::{self},
}; };
use egui::{Label, RichText, Sense}; use egui::{Label, RichText, Sense};
use enostr::KeypairUnowned;
use nostrdb::{Note, NoteReply, Transaction}; use nostrdb::{Note, NoteReply, Transaction};
use super::{contents::NoteContext, NoteOptions}; use super::{contents::NoteContext, NoteOptions};
@@ -11,6 +12,7 @@ use super::{contents::NoteContext, NoteOptions};
#[profiling::function] #[profiling::function]
pub fn reply_desc( pub fn reply_desc(
ui: &mut egui::Ui, ui: &mut egui::Ui,
cur_acc: &Option<KeypairUnowned>,
txn: &Transaction, txn: &Transaction,
note_reply: &NoteReply, note_reply: &NoteReply,
note_context: &mut NoteContext, note_context: &mut NoteContext,
@@ -39,7 +41,7 @@ pub fn reply_desc(
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);
ui::NoteView::new(note_context, note, note_options) ui::NoteView::new(note_context, cur_acc, note, note_options)
.actionbar(false) .actionbar(false)
.wide(true) .wide(true)
.show(ui); .show(ui);

View File

@@ -114,6 +114,10 @@ impl<'a, 'd> ProfileView<'a, 'd> {
&txn, &txn,
self.is_muted, self.is_muted,
self.note_context, self.note_context,
&self
.accounts
.get_selected_account()
.map(|a| (&a.key).into()),
) )
.show(ui) .show(ui)
{ {

View File

@@ -1,4 +1,5 @@
use egui::{vec2, Align, Color32, CornerRadius, RichText, Stroke, TextEdit}; use egui::{vec2, Align, Color32, CornerRadius, RichText, Stroke, TextEdit};
use enostr::KeypairUnowned;
use super::{note::contents::NoteContext, padding}; use super::{note::contents::NoteContext, padding};
use crate::{ use crate::{
@@ -21,6 +22,7 @@ pub struct SearchView<'a, 'd> {
txn: &'a Transaction, txn: &'a Transaction,
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>>,
} }
impl<'a, 'd> SearchView<'a, 'd> { impl<'a, 'd> SearchView<'a, 'd> {
@@ -30,6 +32,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
note_options: NoteOptions, note_options: NoteOptions,
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>>,
) -> Self { ) -> Self {
Self { Self {
txn, txn,
@@ -37,6 +40,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
query, query,
note_options, note_options,
note_context, note_context,
cur_acc,
} }
} }
@@ -79,6 +83,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
self.txn, self.txn,
self.is_muted, self.is_muted,
self.note_context, self.note_context,
self.cur_acc,
) )
.show(ui) .show(ui)
}) })

View File

@@ -3,6 +3,7 @@ use crate::{
timeline::{ThreadSelection, TimelineCache, TimelineKind}, timeline::{ThreadSelection, TimelineCache, TimelineKind},
}; };
use enostr::KeypairUnowned;
use nostrdb::Transaction; use nostrdb::Transaction;
use notedeck::{MuteFun, RootNoteId, UnknownIds}; use notedeck::{MuteFun, RootNoteId, UnknownIds};
use tracing::error; use tracing::error;
@@ -20,6 +21,7 @@ pub struct ThreadView<'a, 'd> {
id_source: egui::Id, id_source: egui::Id,
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>>,
} }
impl<'a, 'd> ThreadView<'a, 'd> { impl<'a, 'd> ThreadView<'a, 'd> {
@@ -31,6 +33,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
note_options: NoteOptions, note_options: NoteOptions,
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>>,
) -> Self { ) -> Self {
let id_source = egui::Id::new("threadscroll_threadview"); let id_source = egui::Id::new("threadscroll_threadview");
ThreadView { ThreadView {
@@ -41,6 +44,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
id_source, id_source,
is_muted, is_muted,
note_context, note_context,
cur_acc,
} }
} }
@@ -108,6 +112,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
&txn, &txn,
self.is_muted, self.is_muted,
self.note_context, self.note_context,
self.cur_acc,
) )
.show(ui) .show(ui)
}) })

View File

@@ -9,6 +9,7 @@ use crate::{
use egui::containers::scroll_area::ScrollBarVisibility; use egui::containers::scroll_area::ScrollBarVisibility;
use egui::{vec2, Direction, Layout, Pos2, Stroke}; use egui::{vec2, Direction, Layout, Pos2, Stroke};
use egui_tabs::TabColor; use egui_tabs::TabColor;
use enostr::KeypairUnowned;
use nostrdb::Transaction; use nostrdb::Transaction;
use notedeck::note::root_note_id_from_selected_id; use notedeck::note::root_note_id_from_selected_id;
use notedeck::MuteFun; use notedeck::MuteFun;
@@ -25,6 +26,7 @@ pub struct TimelineView<'a, 'd> {
reverse: bool, reverse: bool,
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>>,
} }
impl<'a, 'd> TimelineView<'a, 'd> { impl<'a, 'd> TimelineView<'a, 'd> {
@@ -35,6 +37,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
note_options: NoteOptions, note_options: NoteOptions,
cur_acc: &'a Option<KeypairUnowned<'a>>,
) -> Self { ) -> Self {
let reverse = false; let reverse = false;
TimelineView { TimelineView {
@@ -44,6 +47,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
reverse, reverse,
is_muted, is_muted,
note_context, note_context,
cur_acc,
} }
} }
@@ -56,6 +60,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
self.note_options, self.note_options,
self.is_muted, self.is_muted,
self.note_context, self.note_context,
self.cur_acc,
) )
} }
@@ -74,6 +79,7 @@ fn timeline_ui(
note_options: NoteOptions, note_options: NoteOptions,
is_muted: &MuteFun, is_muted: &MuteFun,
note_context: &mut NoteContext, note_context: &mut NoteContext,
cur_acc: &Option<KeypairUnowned>,
) -> Option<NoteAction> { ) -> Option<NoteAction> {
//padding(4.0, ui, |ui| ui.heading("Notifications")); //padding(4.0, ui, |ui| ui.heading("Notifications"));
/* /*
@@ -151,6 +157,7 @@ fn timeline_ui(
&txn, &txn,
is_muted, is_muted,
note_context, note_context,
cur_acc,
) )
.show(ui) .show(ui)
}); });
@@ -317,6 +324,7 @@ pub struct TimelineTabView<'a, 'd> {
txn: &'a Transaction, txn: &'a Transaction,
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>>,
} }
impl<'a, 'd> TimelineTabView<'a, 'd> { impl<'a, 'd> TimelineTabView<'a, 'd> {
@@ -328,6 +336,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
txn: &'a Transaction, txn: &'a Transaction,
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>>,
) -> Self { ) -> Self {
Self { Self {
tab, tab,
@@ -336,6 +345,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
txn, txn,
is_muted, is_muted,
note_context, note_context,
cur_acc,
} }
} }
@@ -382,8 +392,13 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
if !muted { if !muted {
ui::padding(8.0, ui, |ui| { ui::padding(8.0, ui, |ui| {
let resp = let resp = ui::NoteView::new(
ui::NoteView::new(self.note_context, &note, self.note_options).show(ui); self.note_context,
self.cur_acc,
&note,
self.note_options,
)
.show(ui);
if let Some(note_action) = resp.action { if let Some(note_action) = resp.action {
action = Some(note_action) action = Some(note_action)