Branch based on config to note sync for push suppression.

Minor if-let condition and scope reduction; formatting.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-09-08 20:19:41 +00:00
parent 296018f0cc
commit 29c2c8a333
3 changed files with 34 additions and 35 deletions

View File

@@ -134,9 +134,10 @@ pub(crate) async fn sync_events_route(
.log_err()
.ok();
// Record that this user was actively syncing now (for push suppression
// heuristic)
services.presence.note_sync(sender_user).await;
// Record user as actively syncing for push suppression heuristic.
if services.config.suppress_push_when_active {
services.presence.note_sync(sender_user).await;
}
}
let mut since = body

View File

@@ -33,6 +33,7 @@ use ruma::{
AnySyncEphemeralRoomEvent, GlobalAccountDataEventType, push_rules::PushRulesEvent,
receipt::ReceiptType,
},
presence::PresenceState,
push,
serde::Raw,
uint,
@@ -836,40 +837,37 @@ impl Service {
// optional suppression: heuristic combining presence age and recent sync
// activity.
if self
.services
.server
.config
.suppress_push_when_active
{
if let Ok(presence) = self
if self.services.config.suppress_push_when_active
&& 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 is_online = presence.content.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;
}
}

View File

@@ -1094,12 +1094,12 @@
#
#presence_timeout_remote_users = true
# Suppresses push notifications for users marked as active.
# Suppresses push notifications for users marked as active. (Experimental)
#
# When enabled, users with `Online` presence and recent activity
# (based on presence state and sync activity) wont receive push
# notifications, reducing duplicate alerts while they're active
# elsewhere.
# on another client.
#
# Disabled by default to preserve legacy behavior.
#