refactor: impl transitive trust via NoteOptions::TrustMedia

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-09-11 19:37:56 -04:00
parent a8eaea6509
commit 4ac2e59983
4 changed files with 22 additions and 53 deletions

View File

@@ -6,9 +6,7 @@ use crate::{
use egui::{Color32, Hyperlink, Label, RichText}; use egui::{Color32, Hyperlink, Label, RichText};
use nostrdb::{BlockType, Mention, Note, Transaction}; use nostrdb::{BlockType, Mention, Note, Transaction};
use notedeck::Localization; use notedeck::Localization;
use notedeck::{ use notedeck::{time_format, update_imeta_blurhashes, NoteCache, NoteContext, NotedeckTextStyle};
time_format, update_imeta_blurhashes, IsFollowing, NoteCache, NoteContext, NotedeckTextStyle,
};
use notedeck::{JobsCache, RenderableMedia}; use notedeck::{JobsCache, RenderableMedia};
use tracing::warn; use tracing::warn;
@@ -16,7 +14,6 @@ pub struct NoteContents<'a, 'd> {
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
txn: &'a Transaction, txn: &'a Transaction,
note: &'a Note<'a>, note: &'a Note<'a>,
parent: Option<&'a Note<'a>>,
options: NoteOptions, options: NoteOptions,
pub action: Option<NoteAction>, pub action: Option<NoteAction>,
jobs: &'a mut JobsCache, jobs: &'a mut JobsCache,
@@ -28,7 +25,6 @@ impl<'a, 'd> NoteContents<'a, 'd> {
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
txn: &'a Transaction, txn: &'a Transaction,
note: &'a Note, note: &'a Note,
parent: Option<&'a Note>,
options: NoteOptions, options: NoteOptions,
jobs: &'a mut JobsCache, jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
@@ -36,7 +32,6 @@ impl<'a, 'd> NoteContents<'a, 'd> {
note_context, note_context,
txn, txn,
note, note,
parent,
options, options,
action: None, action: None,
jobs, jobs,
@@ -51,7 +46,6 @@ impl egui::Widget for &mut NoteContents<'_, '_> {
self.note_context, self.note_context,
self.txn, self.txn,
self.note, self.note,
self.parent,
self.options, self.options,
self.jobs, self.jobs,
); );
@@ -132,12 +126,10 @@ fn render_note_contents(
note_context: &mut NoteContext, note_context: &mut NoteContext,
txn: &Transaction, txn: &Transaction,
note: &Note, note: &Note,
parent: Option<&Note>,
options: NoteOptions, options: NoteOptions,
jobs: &mut JobsCache, jobs: &mut JobsCache,
) -> NoteResponse { ) -> NoteResponse {
let response = let response = render_undecorated_note_contents(ui, note_context, txn, note, options, jobs);
render_undecorated_note_contents(ui, note_context, txn, note, parent, options, jobs);
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
note_bottom_metadata_ui( note_bottom_metadata_ui(
@@ -178,7 +170,6 @@ fn render_undecorated_note_contents<'a>(
note_context: &mut NoteContext, note_context: &mut NoteContext,
txn: &Transaction, txn: &Transaction,
note: &'a Note, note: &'a Note,
parent: Option<&'a Note>,
options: NoteOptions, options: NoteOptions,
jobs: &mut JobsCache, jobs: &mut JobsCache,
) -> NoteResponse { ) -> NoteResponse {
@@ -383,28 +374,6 @@ fn render_undecorated_note_contents<'a>(
ui.add_space(2.0); ui.add_space(2.0);
let carousel_id = egui::Id::new(("carousel", note.key().expect("expected tx note"))); 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( media_action = image_carousel(
ui, ui,
note_context.img_cache, note_context.img_cache,
@@ -412,7 +381,6 @@ fn render_undecorated_note_contents<'a>(
jobs, jobs,
&supported_medias, &supported_medias,
carousel_id, carousel_id,
trusted_media,
note_context.i18n, note_context.i18n,
options, options,
); );

View File

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

View File

@@ -255,7 +255,6 @@ impl<'a, 'd> NoteView<'a, 'd> {
self.note_context, self.note_context,
txn, txn,
self.note, self.note,
self.parent,
self.flags, self.flags,
self.jobs, self.jobs,
)); ));
@@ -303,6 +302,18 @@ impl<'a, 'd> NoteView<'a, 'd> {
} }
pub fn show(&mut self, ui: &mut egui::Ui) -> NoteResponse { 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) { if self.options().contains(NoteOptions::Textmode) {
NoteResponse::new(self.textmode_ui(ui)) NoteResponse::new(self.textmode_ui(ui))
} else if self.options().contains(NoteOptions::Framed) { } else if self.options().contains(NoteOptions::Framed) {
@@ -426,14 +437,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
}); });
} }
let mut contents = NoteContents::new( let mut contents =
self.note_context, NoteContents::new(self.note_context, txn, self.note, self.flags, self.jobs);
txn,
self.note,
self.parent,
self.flags,
self.jobs,
);
ui.add(&mut contents); ui.add(&mut contents);
@@ -526,14 +531,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
}); });
} }
let mut contents = NoteContents::new( let mut contents =
self.note_context, NoteContents::new(self.note_context, txn, self.note, self.flags, self.jobs);
txn,
self.note,
self.parent,
self.flags,
self.jobs,
);
ui.add(&mut contents); ui.add(&mut contents);
note_action = contents.action.or(note_action); note_action = contents.action.or(note_action);

View File

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