From 557608db9bee05b8152fc5b68c77bc14c1ba06db Mon Sep 17 00:00:00 2001 From: kernelkind Date: Thu, 31 Jul 2025 18:55:25 -0400 Subject: [PATCH] chrome: method to find whether there are unseen notifications Signed-off-by: kernelkind --- crates/notedeck_chrome/src/chrome.rs | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/notedeck_chrome/src/chrome.rs b/crates/notedeck_chrome/src/chrome.rs index 6835e9d7..463e9a3f 100644 --- a/crates/notedeck_chrome/src/chrome.rs +++ b/crates/notedeck_chrome/src/chrome.rs @@ -477,6 +477,38 @@ impl Chrome { } } +fn unseen_notification( + columns: Option<&mut Damus>, + ndb: &nostrdb::Ndb, + current_pk: notedeck::enostr::Pubkey, +) -> bool { + let Some(columns) = columns else { + return false; + }; + + let Some(tl) = columns + .timeline_cache + .get_mut(&TimelineKind::Notifications(current_pk)) + else { + return false; + }; + + let freshness = &mut tl.current_view_mut().freshness; + freshness.update(|timestamp_last_viewed| { + let filter = notedeck_columns::timeline::kind::notifications_filter(¤t_pk) + .since_mut(timestamp_last_viewed); + let txn = Transaction::new(ndb).expect("txn"); + + let Some(res) = ndb.query(&txn, &[filter], 1).ok() else { + return false; + }; + + !res.is_empty() + }); + + freshness.has_unseen() +} + impl notedeck::App for Chrome { fn update(&mut self, ctx: &mut notedeck::AppContext, ui: &mut egui::Ui) -> Option { if let Some(action) = self.show(ctx, ui) {