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

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

View File

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

View File

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

View File

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

View File

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