Merge pull request #137 from fiatjaf/filter-out-messages-from-future

Filter out messages from the future
This commit is contained in:
Michael Dilger 2023-01-14 10:33:04 +13:00 committed by GitHub
commit 191c7a792d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
use crate::comms::{ToMinionMessage, ToMinionPayload}; use crate::comms::{ToMinionMessage, ToMinionPayload};
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use nostr_types::PublicKeyHex; use nostr_types::{Event, EventKind, Id, PublicKeyHex, Unixtime};
use nostr_types::{Event, EventKind, Id};
use parking_lot::RwLock; use parking_lot::RwLock;
use std::collections::HashSet; use std::collections::HashSet;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -187,10 +186,12 @@ impl Feed {
.collect(); .collect();
// Filter further for the general feed // Filter further for the general feed
let now = Unixtime::now().unwrap();
let mut fevents: Vec<Event> = events let mut fevents: Vec<Event> = events
.iter() .iter()
.filter(|e| !GLOBALS.dismissed.blocking_read().contains(&e.id)) .filter(|e| !GLOBALS.dismissed.blocking_read().contains(&e.id))
.filter(|e| pubkeys.contains(&e.pubkey.into())) // something we follow .filter(|e| pubkeys.contains(&e.pubkey.into())) // something we follow
.filter(|e| e.created_at <= now)
.cloned() .cloned()
.collect(); .collect();
fevents.sort_by(|a, b| b.created_at.cmp(&a.created_at)); fevents.sort_by(|a, b| b.created_at.cmp(&a.created_at));