Merge a bunch of fixes from kernel

PRs

* 1141
* 1137
* 1136

kernelkind (10):
      Revert "feat: transitively trust images from parent note"
      feat: enable transitive trust for repost
      fix `NoteUnits` front insertion logic
      fix: don't reset scroll position when switching toolbar
      fix: no longer make the scroll position jump oddly
      fix: repost desc text size on newline
      make `tabs_ui` return `InnerResponse`
      refactor: impl transitive trust via `NoteOptions::TrustMedia`
      refactor: move `profile_body` to fn
      refactor: remove unnecessary code
This commit is contained in:
William Casarin
2025-09-16 11:28:20 -07:00
10 changed files with 242 additions and 245 deletions

View File

@@ -4,11 +4,9 @@ use crate::{
secondary_label,
};
use egui::{Color32, Hyperlink, Label, RichText};
use nostrdb::{BlockType, Mention, Note, Transaction};
use nostrdb::{BlockType, Mention, Note, NoteKey, Transaction};
use notedeck::Localization;
use notedeck::{
time_format, update_imeta_blurhashes, IsFollowing, NoteCache, NoteContext, NotedeckTextStyle,
};
use notedeck::{time_format, update_imeta_blurhashes, NoteCache, NoteContext, NotedeckTextStyle};
use notedeck::{JobsCache, RenderableMedia};
use tracing::warn;
@@ -16,7 +14,6 @@ pub struct NoteContents<'a, 'd> {
note_context: &'a mut NoteContext<'d>,
txn: &'a Transaction,
note: &'a Note<'a>,
parent: Option<&'a Note<'a>>,
options: NoteOptions,
pub action: Option<NoteAction>,
jobs: &'a mut JobsCache,
@@ -28,7 +25,6 @@ impl<'a, 'd> NoteContents<'a, 'd> {
note_context: &'a mut NoteContext<'d>,
txn: &'a Transaction,
note: &'a Note,
parent: Option<&'a Note>,
options: NoteOptions,
jobs: &'a mut JobsCache,
) -> Self {
@@ -36,7 +32,6 @@ impl<'a, 'd> NoteContents<'a, 'd> {
note_context,
txn,
note,
parent,
options,
action: None,
jobs,
@@ -51,7 +46,6 @@ impl egui::Widget for &mut NoteContents<'_, '_> {
self.note_context,
self.txn,
self.note,
self.parent,
self.options,
self.jobs,
);
@@ -87,7 +81,7 @@ pub fn render_note_preview(
note_context: &mut NoteContext,
txn: &Transaction,
id: &[u8; 32],
parent: Option<&Note>,
parent: NoteKey,
note_options: NoteOptions,
jobs: &mut JobsCache,
) -> NoteResponse {
@@ -118,12 +112,10 @@ pub fn render_note_preview(
*/
};
let mut view = NoteView::new(note_context, &note, note_options, jobs).preview_style();
if let Some(parent) = parent {
view = view.parent(parent);
}
view.show(ui)
NoteView::new(note_context, &note, note_options, jobs)
.preview_style()
.parent(parent)
.show(ui)
}
/// Render note contents and surrounding info (client name, full date timestamp)
@@ -132,12 +124,10 @@ fn render_note_contents(
note_context: &mut NoteContext,
txn: &Transaction,
note: &Note,
parent: Option<&Note>,
options: NoteOptions,
jobs: &mut JobsCache,
) -> NoteResponse {
let response =
render_undecorated_note_contents(ui, note_context, txn, note, parent, options, jobs);
let response = render_undecorated_note_contents(ui, note_context, txn, note, options, jobs);
ui.horizontal_wrapped(|ui| {
note_bottom_metadata_ui(
@@ -178,7 +168,6 @@ fn render_undecorated_note_contents<'a>(
note_context: &mut NoteContext,
txn: &Transaction,
note: &'a Note,
parent: Option<&'a Note>,
options: NoteOptions,
jobs: &mut JobsCache,
) -> NoteResponse {
@@ -366,7 +355,7 @@ fn render_undecorated_note_contents<'a>(
});
let preview_note_action = inline_note.and_then(|(id, _)| {
render_note_preview(ui, note_context, txn, id, Some(note), options, jobs)
render_note_preview(ui, note_context, txn, id, note_key, options, jobs)
.action
.map(|a| match a {
NoteAction::Note { note_id, .. } => NoteAction::Note {
@@ -383,28 +372,6 @@ fn render_undecorated_note_contents<'a>(
ui.add_space(2.0);
let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note")));
let is_self = note.pubkey()
== note_context
.accounts
.get_selected_account()
.key
.pubkey
.bytes();
let trusted_media = {
let is_followed = |pk| {
matches!(
note_context
.accounts
.get_selected_account()
.is_following(pk),
IsFollowing::Yes
)
};
is_self || is_followed(note.pubkey()) || parent.is_some_and(|p| is_followed(p.pubkey()))
};
media_action = image_carousel(
ui,
note_context.img_cache,
@@ -412,7 +379,6 @@ fn render_undecorated_note_contents<'a>(
jobs,
&supported_medias,
carousel_id,
trusted_media,
note_context.i18n,
options,
);

View File

@@ -33,7 +33,6 @@ pub fn image_carousel(
jobs: &mut JobsCache,
medias: &[RenderableMedia],
carousel_id: egui::Id,
trusted_media: bool,
i18n: &mut Localization,
note_options: NoteOptions,
) -> Option<MediaAction> {
@@ -68,7 +67,7 @@ pub fn image_carousel(
job_pool,
jobs,
media,
trusted_media,
note_options.contains(NoteOptions::TrustMedia),
i18n,
size,
if note_options.contains(NoteOptions::NoAnimations) {

View File

@@ -32,7 +32,7 @@ use notedeck::{
pub struct NoteView<'a, 'd> {
note_context: &'a mut NoteContext<'d>,
parent: Option<&'a Note<'a>>,
parent: Option<NoteKey>,
note: &'a nostrdb::Note<'a>,
flags: NoteOptions,
jobs: &'a mut JobsCache,
@@ -85,7 +85,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
flags: NoteOptions,
jobs: &'a mut JobsCache,
) -> Self {
let parent: Option<&Note> = None;
let parent: Option<NoteKey> = None;
Self {
note_context,
@@ -209,7 +209,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
}
#[inline]
pub fn parent(mut self, parent: &'a Note<'a>) -> Self {
pub fn parent(mut self, parent: NoteKey) -> Self {
self.parent = Some(parent);
self
}
@@ -255,7 +255,6 @@ impl<'a, 'd> NoteView<'a, 'd> {
self.note_context,
txn,
self.note,
self.parent,
self.flags,
self.jobs,
));
@@ -303,6 +302,18 @@ impl<'a, 'd> NoteView<'a, 'd> {
}
pub fn show(&mut self, ui: &mut egui::Ui) -> NoteResponse {
if !self.flags.contains(NoteOptions::TrustMedia) {
let acc = self.note_context.accounts.get_selected_account();
if self.note.pubkey() == acc.key.pubkey.bytes()
|| matches!(
acc.is_following(self.note.pubkey()),
notedeck::IsFollowing::Yes
)
{
self.flags = self.flags.union(NoteOptions::TrustMedia);
}
}
if self.options().contains(NoteOptions::Textmode) {
NoteResponse::new(self.textmode_ui(ui))
} else if self.options().contains(NoteOptions::Framed) {
@@ -426,14 +437,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
});
}
let mut contents = NoteContents::new(
self.note_context,
txn,
self.note,
self.parent,
self.flags,
self.jobs,
);
let mut contents =
NoteContents::new(self.note_context, txn, self.note, self.flags, self.jobs);
ui.add(&mut contents);
@@ -526,14 +531,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
});
}
let mut contents = NoteContents::new(
self.note_context,
txn,
self.note,
self.parent,
self.flags,
self.jobs,
);
let mut contents =
NoteContents::new(self.note_context, txn, self.note, self.flags, self.jobs);
ui.add(&mut contents);
note_action = contents.action.or(note_action);
@@ -577,12 +576,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
.ndb
.get_profile_by_pubkey(txn, self.note.pubkey());
let hitbox_id = note_hitbox_id(
note_key,
self.options(),
self.parent
.map(|n| n.key().expect("todo: support non-db notes")),
);
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
// wide design
@@ -749,7 +743,7 @@ fn note_hitbox_id(
fn maybe_note_hitbox(ui: &mut egui::Ui, hitbox_id: egui::Id) -> Option<Response> {
ui.ctx()
.data_mut(|d| d.get_persisted(hitbox_id))
.data_mut(|d| d.get_temp(hitbox_id))
.map(|note_size: Vec2| {
// The hitbox should extend the entire width of the
// container. The hitbox height was cached last layout.

View File

@@ -44,6 +44,9 @@ bitflags! {
/// The note is a notification
const Notification = 1 << 19;
/// There is enough trust to show media in this note
const TrustMedia = 1 << 20;
}
}