feat(presence,push) optionally suppress push notifications for active users

This commit is contained in:
tototomate123
2025-09-02 14:26:12 +02:00
committed by Jason Volk
parent 1be7fd9247
commit b5a9884194
5 changed files with 67 additions and 4 deletions

View File

@@ -19,14 +19,13 @@ use ruma::{
MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName,
UInt,
api::{
appservice::event::push_events::v1::EphemeralData,
federation::transactions::{
appservice::event::push_events::v1::EphemeralData, federation::transactions::{
edu::{
DeviceListUpdateContent, Edu, PresenceContent, PresenceUpdate, ReceiptContent,
ReceiptData, ReceiptMap,
},
send_transaction_message,
},
}
},
device_id,
events::{
@@ -834,6 +833,26 @@ impl Service {
continue;
}
// optional suppression: heuristic combining presence age and recent sync activity.
if self.services.server.config.suppress_push_when_active {
if let Ok(presence) = self.services.presence.get_presence(&user_id).await {
let is_online = presence.content.presence == ruma::presence::PresenceState::Online;
let presence_age_ms = presence
.content
.last_active_ago
.map(u64::from)
.unwrap_or(u64::MAX);
let sync_gap_ms = self.services.presence.last_sync_gap_ms(&user_id).await;
let considered_active = is_online
&& presence_age_ms < 65_000
&& sync_gap_ms.is_some_and(|gap| gap < 32_000);
if considered_active {
trace!(?user_id, presence_age_ms, sync_gap_ms, "suppressing push: active heuristic");
continue;
}
}
}
let rules_for_user = self
.services
.account_data