Use a global viewed events map that we can later save

This commit is contained in:
Mike Dilger 2023-03-07 16:36:18 +13:00 committed by Mike Dilger
parent 20b7ac06f9
commit fd829f3fd2
3 changed files with 12 additions and 4 deletions

View File

@ -47,6 +47,13 @@ pub struct Globals {
/// stored with Url they came from and Subscription they came in on
pub incoming_events: RwLock<Vec<(Event, RelayUrl, Option<String>)>>,
/// Viewed events
pub viewed_events: DashSet<Id>,
/// Periodically this flushes to the database and clears.
/// We need the rwlock to drain it properly
pub new_viewed_events: RwLock<DashSet<Id>>,
/// All relationships between events
pub relationships: RwLock<HashMap<Id, Vec<(Id, Relationship)>>>,
@ -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(),

View File

@ -86,7 +86,7 @@ pub(super) fn render_note(
}
};
let is_new = !app.viewed.contains(&note_data.event.id);
let is_new = !GLOBALS.viewed_events.contains(&note_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);
}
});

View File

@ -115,7 +115,6 @@ struct GossipUi {
// Post rendering
render_raw: Option<Id>,
render_qr: Option<Id>,
viewed: HashSet<Id>,
approved: HashSet<Id>, // content warning posts
height: HashMap<Id, f32>,
@ -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,