mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 03:33:53 +00:00
Feed: track get_my_event_ids(), get_followed_event_ids()
This commit is contained in:
parent
b2de9452ff
commit
61597e841b
49
src/feed.rs
49
src/feed.rs
@ -8,6 +8,10 @@ pub struct Feed {
|
||||
// We only recompute the feed at specified intervals
|
||||
interval_ms: u32,
|
||||
last_computed: Instant,
|
||||
|
||||
// We track these to update subscriptions on them
|
||||
my_event_ids: Vec<Id>,
|
||||
followed_event_ids: Vec<Id>,
|
||||
}
|
||||
|
||||
impl Feed {
|
||||
@ -16,6 +20,8 @@ impl Feed {
|
||||
feed: Vec::new(),
|
||||
interval_ms: 1000, // Every second, until we load from settings
|
||||
last_computed: Instant::now(),
|
||||
my_event_ids: Vec::new(),
|
||||
followed_event_ids: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,16 +35,57 @@ impl Feed {
|
||||
self.feed.clone()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_my_event_ids(&self) -> Vec<Id> {
|
||||
// we assume the main get() happens fast enough to recompute for us.
|
||||
self.my_event_ids.clone()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_followed_event_ids(&self) -> Vec<Id> {
|
||||
// we assume the main get() happens fast enough to recompute for us.
|
||||
self.followed_event_ids.clone()
|
||||
}
|
||||
|
||||
fn recompute(&mut self) {
|
||||
let settings = GLOBALS.settings.blocking_read().clone();
|
||||
self.interval_ms = settings.feed_recompute_interval_ms;
|
||||
|
||||
let mut events: Vec<Event> = GLOBALS
|
||||
let events: Vec<Event> = GLOBALS
|
||||
.events
|
||||
.blocking_read()
|
||||
.iter()
|
||||
.map(|(_, e)| e)
|
||||
.filter(|e| e.kind == EventKind::TextNote)
|
||||
.map(|e| e.to_owned())
|
||||
.collect();
|
||||
|
||||
// My event ids
|
||||
if let Some(pubkey) = GLOBALS.signer.blocking_read().public_key() {
|
||||
self.my_event_ids = events
|
||||
.iter()
|
||||
.filter_map(|e| if e.pubkey == pubkey { Some(e.id) } else { None })
|
||||
.collect();
|
||||
} else {
|
||||
self.my_event_ids = vec![];
|
||||
}
|
||||
|
||||
// Followed event ids
|
||||
let followed_pubkeys = GLOBALS.people.blocking_read().get_followed_pubkeys();
|
||||
self.followed_event_ids = events
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
if followed_pubkeys.contains(&e.pubkey.into()) {
|
||||
Some(e.id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Filter further for the feed
|
||||
let mut events: Vec<Event> = events
|
||||
.iter()
|
||||
.filter(|e| !GLOBALS.dismissed.blocking_read().contains(&e.id))
|
||||
.filter(|e| {
|
||||
if settings.view_threaded {
|
||||
|
Loading…
Reference in New Issue
Block a user