refactor: replace notification bool prop drill with note option

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-09-10 12:04:00 -07:00
parent 7b4c96df91
commit f889b54ed9
3 changed files with 15 additions and 21 deletions

View File

@@ -234,7 +234,7 @@ impl HybridFilter {
HybridFilter::Split(SplitFilter { local, remote }) HybridFilter::Split(SplitFilter { local, remote })
} }
pub fn local(&self) -> NdbQueryPackages { pub fn local(&self) -> NdbQueryPackages<'_> {
match self { match self {
Self::Split(split) => NdbQueryPackages { Self::Split(split) => NdbQueryPackages {
packages: split.local.iter().map(NdbQueryPackage::borrow).collect(), packages: split.local.iter().map(NdbQueryPackage::borrow).collect(),
@@ -305,7 +305,7 @@ pub struct NdbQueryPackage {
} }
impl NdbQueryPackage { impl NdbQueryPackage {
pub fn borrow(&self) -> NdbQueryPackageUnowned { pub fn borrow(&self) -> NdbQueryPackageUnowned<'_> {
NdbQueryPackageUnowned { NdbQueryPackageUnowned {
filters: &self.filters, filters: &self.filters,
kind: Some(self.kind.clone()), kind: Some(self.kind.clone()),

View File

@@ -88,7 +88,7 @@ fn timeline_ui(
ui: &mut egui::Ui, ui: &mut egui::Ui,
timeline_id: &TimelineKind, timeline_id: &TimelineKind,
timeline_cache: &mut TimelineCache, timeline_cache: &mut TimelineCache,
note_options: NoteOptions, mut note_options: NoteOptions,
note_context: &mut NoteContext, note_context: &mut NoteContext,
jobs: &mut JobsCache, jobs: &mut JobsCache,
col: usize, col: usize,
@@ -181,6 +181,10 @@ fn timeline_ui(
let txn = Transaction::new(note_context.ndb).expect("failed to create txn"); let txn = Transaction::new(note_context.ndb).expect("failed to create txn");
if matches!(timeline_id, TimelineKind::Notifications(_)) {
note_options.set(NoteOptions::Notification, true)
}
TimelineTabView::new( TimelineTabView::new(
timeline.current_view(), timeline.current_view(),
note_options, note_options,
@@ -188,7 +192,6 @@ fn timeline_ui(
note_context, note_context,
jobs, jobs,
) )
.notifications(matches!(timeline_id, TimelineKind::Notifications(_)))
.show(ui) .show(ui)
}); });
@@ -376,7 +379,6 @@ fn shrink_range_to_width(range: egui::Rangef, width: f32) -> egui::Rangef {
} }
pub struct TimelineTabView<'a, 'd> { pub struct TimelineTabView<'a, 'd> {
notifications: bool,
tab: &'a TimelineTab, tab: &'a TimelineTab,
note_options: NoteOptions, note_options: NoteOptions,
txn: &'a Transaction, txn: &'a Transaction,
@@ -394,7 +396,6 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
jobs: &'a mut JobsCache, jobs: &'a mut JobsCache,
) -> Self { ) -> Self {
Self { Self {
notifications: false,
tab, tab,
note_options, note_options,
txn, txn,
@@ -403,11 +404,6 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
} }
} }
pub fn notifications(mut self, notifications: bool) -> Self {
self.notifications = notifications;
self
}
pub fn show(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> { pub fn show(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
let mut action: Option<NoteAction> = None; let mut action: Option<NoteAction> = None;
let len = self.tab.units.len(); let len = self.tab.units.len();
@@ -509,7 +505,6 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
self.txn, self.txn,
&underlying_note, &underlying_note,
repost_unit, repost_unit,
self.notifications,
), ),
}, },
} }
@@ -727,12 +722,11 @@ fn render_reaction_cluster(
render_composite_entry( render_composite_entry(
ui, ui,
note_context, note_context,
note_options, note_options | NoteOptions::Notification,
jobs, jobs,
underlying_note, underlying_note,
profiles_to_show, profiles_to_show,
CompositeType::Reaction, CompositeType::Reaction,
true,
) )
} }
@@ -745,7 +739,6 @@ fn render_composite_entry(
underlying_note: &nostrdb::Note<'_>, underlying_note: &nostrdb::Note<'_>,
profiles_to_show: Vec<ProfileEntry>, profiles_to_show: Vec<ProfileEntry>,
composite_type: CompositeType, composite_type: CompositeType,
notification: bool,
) -> RenderEntryResponse { ) -> RenderEntryResponse {
let first_name = get_display_name(profiles_to_show.iter().find_map(|opt| opt.record.as_ref())) let first_name = get_display_name(profiles_to_show.iter().find_map(|opt| opt.record.as_ref()))
.name() .name()
@@ -782,7 +775,7 @@ fn render_composite_entry(
profiles_to_show, profiles_to_show,
&composite_type, &composite_type,
note_context.img_cache, note_context.img_cache,
notification, note_options.contains(NoteOptions::Notification),
) )
}, },
) )
@@ -797,7 +790,7 @@ fn render_composite_entry(
&first_name, &first_name,
num_profiles, num_profiles,
referenced_type, referenced_type,
notification, note_options.contains(NoteOptions::Notification),
); );
let galley = ui.painter().layout_no_wrap( let galley = ui.painter().layout_no_wrap(
description.clone(), description.clone(),
@@ -846,7 +839,7 @@ fn render_composite_entry(
let resp = ui let resp = ui
.horizontal(|ui| { .horizontal(|ui| {
let mut options = note_options; let mut options = note_options;
if notification { if options.contains(NoteOptions::Notification) {
options = options options = options
.difference(NoteOptions::ActionBar | NoteOptions::OptionsButton) .difference(NoteOptions::ActionBar | NoteOptions::OptionsButton)
.union(NoteOptions::NotificationPreview); .union(NoteOptions::NotificationPreview);
@@ -947,7 +940,6 @@ fn render_repost_cluster(
txn: &Transaction, txn: &Transaction,
underlying_note: &Note, underlying_note: &Note,
repost: &RepostUnit, repost: &RepostUnit,
notifications: bool,
) -> RenderEntryResponse { ) -> RenderEntryResponse {
let profiles_to_show: Vec<ProfileEntry> = repost let profiles_to_show: Vec<ProfileEntry> = repost
.reposts .reposts
@@ -967,7 +959,6 @@ fn render_repost_cluster(
underlying_note, underlying_note,
profiles_to_show, profiles_to_show,
CompositeType::Repost, CompositeType::Repost,
notifications,
) )
} }

View File

@@ -39,8 +39,11 @@ bitflags! {
/// no animation override (accessibility) /// no animation override (accessibility)
const NoAnimations = 1 << 17; const NoAnimations = 1 << 17;
/// Styled for a notification preview /// The note should be displayed as a preview of the underlying note of a composite unit
const NotificationPreview = 1 << 18; const NotificationPreview = 1 << 18;
/// The note is a notification
const Notification = 1 << 19;
} }
} }