|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
use std::collections::VecDeque; |
|
|
|
|
use std::sync::Arc; |
|
|
|
|
use std::time::{Duration, Instant}; |
|
|
|
|
|
|
|
|
@ -29,6 +30,20 @@ pub struct GroupHandle { |
|
|
|
|
pub client: FediClient, |
|
|
|
|
pub config: GroupConfig, |
|
|
|
|
pub cc: Arc<CommonConfig>, |
|
|
|
|
pub internal: GroupInternal, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
|
pub struct GroupInternal { |
|
|
|
|
recently_seen_notif_statuses: VecDeque<String>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Default for GroupInternal { |
|
|
|
|
fn default() -> Self { |
|
|
|
|
Self { |
|
|
|
|
recently_seen_notif_statuses: VecDeque::new() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO move other options to common_config!
|
|
|
|
@ -57,7 +72,6 @@ macro_rules! grp_info { |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[allow(unused)] |
|
|
|
|
macro_rules! grp_trace { |
|
|
|
|
($self:ident, $f:expr) => { |
|
|
|
|
::log::trace!(concat!("(@{}) ", $f), $self.config.get_acct()); |
|
|
|
@ -234,7 +248,13 @@ impl GroupHandle { |
|
|
|
|
|
|
|
|
|
async fn handle_notification(&mut self, n: Notification) -> Result<(), GroupError> { |
|
|
|
|
grp_debug!(self, "Handling notif #{}", n.id); |
|
|
|
|
grp_trace!(self, "{:?}", n); |
|
|
|
|
|
|
|
|
|
let ts = n.timestamp_millis(); |
|
|
|
|
if ts < self.config.get_last_notif() { |
|
|
|
|
grp_debug!(self, "Notif is too old, discard"); |
|
|
|
|
return Ok(()); |
|
|
|
|
} |
|
|
|
|
self.config.set_last_notif(ts); |
|
|
|
|
|
|
|
|
|
let group_acct = self.config.get_acct().to_string(); |
|
|
|
@ -254,9 +274,18 @@ impl GroupHandle { |
|
|
|
|
match n.notification_type { |
|
|
|
|
NotificationType::Mention => { |
|
|
|
|
if let Some(status) = n.status { |
|
|
|
|
if self.internal.recently_seen_notif_statuses.contains(&status.id) { |
|
|
|
|
grp_debug!(self, "Already saw this notif, discard"); |
|
|
|
|
} else { |
|
|
|
|
self.internal.recently_seen_notif_statuses.push_front(status.id.clone()); |
|
|
|
|
while self.internal.recently_seen_notif_statuses.len() > 64 { |
|
|
|
|
let _ = self.internal.recently_seen_notif_statuses.pop_back(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.handle_mention_status(status).await?; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
NotificationType::Follow => { |
|
|
|
|
grp_info!(self, "New follower!"); |
|
|
|
|
// Just greet the user always
|
|
|
|
@ -273,6 +302,8 @@ impl GroupHandle { |
|
|
|
|
/// Handle a non-mention status for tags
|
|
|
|
|
async fn handle_status(&mut self, s: Status) -> Result<(), GroupError> { |
|
|
|
|
grp_debug!(self, "Handling status #{}", s.id); |
|
|
|
|
grp_trace!(self, "{:?}", s); |
|
|
|
|
|
|
|
|
|
let ts = s.timestamp_millis(); |
|
|
|
|
self.config.set_last_status(ts); |
|
|
|
|
|
|
|
|
@ -396,6 +427,7 @@ impl GroupHandle { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grp_debug!(self, "Inspecting notif {}", NotificationDisplay(&n)); |
|
|
|
|
grp_trace!(self, "{:?}", n); |
|
|
|
|
notifs_to_handle.push(n); |
|
|
|
|
num += 1; |
|
|
|
|
if num > self.cc.max_catchup_notifs { |
|
|
|
@ -449,6 +481,7 @@ impl GroupHandle { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grp_debug!(self, "Inspecting status {}", StatusDisplay(&s)); |
|
|
|
|
grp_trace!(self, "{:?}", s); |
|
|
|
|
|
|
|
|
|
if newest_status.is_none() { |
|
|
|
|
newest_status = Some(ts); |
|
|
|
|