commit 4ac2e5998350eaed994fc2fe7d7961df4f554911
parent a8eaea650922288d6884be06484cbc94307dceaf
Author: kernelkind <kernelkind@gmail.com>
Date: Thu, 11 Sep 2025 19:37:56 -0400
refactor: impl transitive trust via `NoteOptions::TrustMedia`
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
4 files changed, 22 insertions(+), 53 deletions(-)
diff --git a/crates/notedeck_ui/src/note/contents.rs b/crates/notedeck_ui/src/note/contents.rs
@@ -6,9 +6,7 @@ use crate::{
use egui::{Color32, Hyperlink, Label, RichText};
use nostrdb::{BlockType, Mention, Note, 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,
);
@@ -132,12 +126,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 +170,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 {
@@ -383,28 +374,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 +381,6 @@ fn render_undecorated_note_contents<'a>(
jobs,
&supported_medias,
carousel_id,
- trusted_media,
note_context.i18n,
options,
);
diff --git a/crates/notedeck_ui/src/note/media.rs b/crates/notedeck_ui/src/note/media.rs
@@ -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) {
diff --git a/crates/notedeck_ui/src/note/mod.rs b/crates/notedeck_ui/src/note/mod.rs
@@ -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);
diff --git a/crates/notedeck_ui/src/note/options.rs b/crates/notedeck_ui/src/note/options.rs
@@ -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;
}
}