From fd829f3fd259c0154bf63113eea6a7908a9a38e8 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Tue, 7 Mar 2023 16:36:18 +1300 Subject: [PATCH] Use a global viewed events map that we can later save --- src/globals.rs | 9 +++++++++ src/ui/feed/note/mod.rs | 5 +++-- src/ui/mod.rs | 2 -- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/globals.rs b/src/globals.rs index 5931a7e4..5435786a 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -47,6 +47,13 @@ pub struct Globals { /// stored with Url they came from and Subscription they came in on pub incoming_events: RwLock)>>, + /// Viewed events + pub viewed_events: DashSet, + + /// Periodically this flushes to the database and clears. + /// We need the rwlock to drain it properly + pub new_viewed_events: RwLock>, + /// All relationships between events pub relationships: RwLock>>, @@ -116,6 +123,8 @@ lazy_static! { tmp_overlord_receiver: Mutex::new(Some(tmp_overlord_receiver)), events: Events::new(), incoming_events: RwLock::new(Vec::new()), + viewed_events: DashSet::new(), + new_viewed_events: RwLock::new(DashSet::new()), relationships: RwLock::new(HashMap::new()), people: People::new(), all_relays: DashMap::new(), diff --git a/src/ui/feed/note/mod.rs b/src/ui/feed/note/mod.rs index 22186e32..4afff099 100644 --- a/src/ui/feed/note/mod.rs +++ b/src/ui/feed/note/mod.rs @@ -86,7 +86,7 @@ pub(super) fn render_note( } }; - let is_new = !app.viewed.contains(¬e_data.event.id); + let is_new = !GLOBALS.viewed_events.contains(¬e_data.event.id); let is_main_event: bool = { let feed_kind = GLOBALS.feed.get_feed_kind(); @@ -143,7 +143,8 @@ pub(super) fn render_note( // Mark post as viewed if hovered AND we are not scrolling if inner_response.response.hovered() && app.current_scroll_offset == 0.0 { - app.viewed.insert(id); + GLOBALS.viewed_events.insert(id); + GLOBALS.new_viewed_events.blocking_write().insert(id); } }); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 65818651..f83292e5 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -115,7 +115,6 @@ struct GossipUi { // Post rendering render_raw: Option, render_qr: Option, - viewed: HashSet, approved: HashSet, // content warning posts height: HashMap, @@ -260,7 +259,6 @@ impl GossipUi { qr_codes: HashMap::new(), render_raw: None, render_qr: None, - viewed: HashSet::new(), approved: HashSet::new(), height: HashMap::new(), person_qr: None,