mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-22 18:54:19 +01:00
feat: transitively trust images from parent note
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -410,7 +410,7 @@ impl<'a, 'd> PostView<'a, 'd> {
|
|||||||
self.note_context,
|
self.note_context,
|
||||||
txn,
|
txn,
|
||||||
id.bytes(),
|
id.bytes(),
|
||||||
nostrdb::NoteKey::new(0),
|
None,
|
||||||
self.note_options,
|
self.note_options,
|
||||||
self.jobs,
|
self.jobs,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::{
|
|||||||
secondary_label,
|
secondary_label,
|
||||||
};
|
};
|
||||||
use egui::{Color32, Hyperlink, Label, RichText};
|
use egui::{Color32, Hyperlink, Label, RichText};
|
||||||
use nostrdb::{BlockType, Mention, Note, NoteKey, Transaction};
|
use nostrdb::{BlockType, Mention, Note, Transaction};
|
||||||
use notedeck::Localization;
|
use notedeck::Localization;
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
time_format, update_imeta_blurhashes, IsFollowing, NoteCache, NoteContext, NotedeckTextStyle,
|
time_format, update_imeta_blurhashes, IsFollowing, NoteCache, NoteContext, NotedeckTextStyle,
|
||||||
@@ -16,6 +16,7 @@ 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,
|
||||||
@@ -27,6 +28,7 @@ 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 {
|
||||||
@@ -34,6 +36,7 @@ impl<'a, 'd> NoteContents<'a, 'd> {
|
|||||||
note_context,
|
note_context,
|
||||||
txn,
|
txn,
|
||||||
note,
|
note,
|
||||||
|
parent,
|
||||||
options,
|
options,
|
||||||
action: None,
|
action: None,
|
||||||
jobs,
|
jobs,
|
||||||
@@ -48,6 +51,7 @@ 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,
|
||||||
);
|
);
|
||||||
@@ -83,7 +87,7 @@ pub fn render_note_preview(
|
|||||||
note_context: &mut NoteContext,
|
note_context: &mut NoteContext,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
id: &[u8; 32],
|
id: &[u8; 32],
|
||||||
parent: NoteKey,
|
parent: Option<&Note>,
|
||||||
note_options: NoteOptions,
|
note_options: NoteOptions,
|
||||||
jobs: &mut JobsCache,
|
jobs: &mut JobsCache,
|
||||||
) -> NoteResponse {
|
) -> NoteResponse {
|
||||||
@@ -114,10 +118,12 @@ pub fn render_note_preview(
|
|||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
NoteView::new(note_context, ¬e, note_options, jobs)
|
let mut view = NoteView::new(note_context, ¬e, note_options, jobs).preview_style();
|
||||||
.preview_style()
|
if let Some(parent) = parent {
|
||||||
.parent(parent)
|
view = view.parent(parent);
|
||||||
.show(ui)
|
}
|
||||||
|
|
||||||
|
view.show(ui)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render note contents and surrounding info (client name, full date timestamp)
|
/// Render note contents and surrounding info (client name, full date timestamp)
|
||||||
@@ -126,10 +132,12 @@ 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 = render_undecorated_note_contents(ui, note_context, txn, note, options, jobs);
|
let response =
|
||||||
|
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(
|
||||||
@@ -170,6 +178,7 @@ 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 {
|
||||||
@@ -357,7 +366,7 @@ fn render_undecorated_note_contents<'a>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let preview_note_action = inline_note.and_then(|(id, _)| {
|
let preview_note_action = inline_note.and_then(|(id, _)| {
|
||||||
render_note_preview(ui, note_context, txn, id, note_key, options, jobs)
|
render_note_preview(ui, note_context, txn, id, Some(note), options, jobs)
|
||||||
.action
|
.action
|
||||||
.map(|a| match a {
|
.map(|a| match a {
|
||||||
NoteAction::Note { note_id, .. } => NoteAction::Note {
|
NoteAction::Note { note_id, .. } => NoteAction::Note {
|
||||||
@@ -382,12 +391,19 @@ fn render_undecorated_note_contents<'a>(
|
|||||||
.pubkey
|
.pubkey
|
||||||
.bytes();
|
.bytes();
|
||||||
|
|
||||||
let trusted_media = is_self
|
let trusted_media = {
|
||||||
|| note_context
|
let is_followed = |pk| {
|
||||||
|
matches!(
|
||||||
|
note_context
|
||||||
.accounts
|
.accounts
|
||||||
.get_selected_account()
|
.get_selected_account()
|
||||||
.is_following(note.pubkey())
|
.is_following(pk),
|
||||||
== IsFollowing::Yes;
|
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,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ use notedeck::{
|
|||||||
|
|
||||||
pub struct NoteView<'a, 'd> {
|
pub struct NoteView<'a, 'd> {
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
parent: Option<NoteKey>,
|
parent: Option<&'a Note<'a>>,
|
||||||
note: &'a nostrdb::Note<'a>,
|
note: &'a nostrdb::Note<'a>,
|
||||||
flags: NoteOptions,
|
flags: NoteOptions,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
@@ -90,7 +90,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
flags: NoteOptions,
|
flags: NoteOptions,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let parent: Option<NoteKey> = None;
|
let parent: Option<&Note> = None;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
note_context,
|
note_context,
|
||||||
@@ -214,7 +214,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parent(mut self, parent: NoteKey) -> Self {
|
pub fn parent(mut self, parent: &'a Note<'a>) -> Self {
|
||||||
self.parent = Some(parent);
|
self.parent = Some(parent);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -260,6 +260,7 @@ 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,
|
||||||
));
|
));
|
||||||
@@ -483,8 +484,14 @@ 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.jobs);
|
self.note_context,
|
||||||
|
txn,
|
||||||
|
self.note,
|
||||||
|
self.parent,
|
||||||
|
self.flags,
|
||||||
|
self.jobs,
|
||||||
|
);
|
||||||
|
|
||||||
ui.add(&mut contents);
|
ui.add(&mut contents);
|
||||||
|
|
||||||
@@ -577,8 +584,14 @@ 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.jobs);
|
self.note_context,
|
||||||
|
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);
|
||||||
@@ -622,7 +635,12 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
.ndb
|
.ndb
|
||||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||||
|
|
||||||
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
|
let hitbox_id = note_hitbox_id(
|
||||||
|
note_key,
|
||||||
|
self.options(),
|
||||||
|
self.parent
|
||||||
|
.map(|n| n.key().expect("todo: support non-db notes")),
|
||||||
|
);
|
||||||
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
||||||
|
|
||||||
// wide design
|
// wide design
|
||||||
|
|||||||
Reference in New Issue
Block a user