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() .log_err()
.ok(); .ok();
// Record that this user was actively syncing now (for push suppression // Record user as actively syncing for push suppression heuristic.
// heuristic) if services.config.suppress_push_when_active {
services.presence.note_sync(sender_user).await; services.presence.note_sync(sender_user).await;
}
} }
let mut since = body let mut since = body

View File

@@ -33,6 +33,7 @@ use ruma::{
AnySyncEphemeralRoomEvent, GlobalAccountDataEventType, push_rules::PushRulesEvent, AnySyncEphemeralRoomEvent, GlobalAccountDataEventType, push_rules::PushRulesEvent,
receipt::ReceiptType, receipt::ReceiptType,
}, },
presence::PresenceState,
push, push,
serde::Raw, serde::Raw,
uint, uint,
@@ -836,40 +837,37 @@ impl Service {
// optional suppression: heuristic combining presence age and recent sync // optional suppression: heuristic combining presence age and recent sync
// activity. // activity.
if self if self.services.config.suppress_push_when_active
.services && let Ok(presence) = self
.server
.config
.suppress_push_when_active
{
if let Ok(presence) = self
.services .services
.presence .presence
.get_presence(&user_id) .get_presence(&user_id)
.await .await
{ {
let is_online = let is_online = presence.content.presence == PresenceState::Online;
presence.content.presence == ruma::presence::PresenceState::Online;
let presence_age_ms = presence let presence_age_ms = presence
.content .content
.last_active_ago .last_active_ago
.map(u64::from) .map(u64::from)
.unwrap_or(u64::MAX); .unwrap_or(u64::MAX);
let sync_gap_ms = self
.services let sync_gap_ms = self
.presence .services
.last_sync_gap_ms(&user_id) .presence
.await; .last_sync_gap_ms(&user_id)
let considered_active = is_online .await;
&& presence_age_ms < 65_000
&& sync_gap_ms.is_some_and(|gap| gap < 32_000); let considered_active = is_online
if considered_active { && presence_age_ms < 65_000
trace!( && sync_gap_ms.is_some_and(|gap| gap < 32_000);
?user_id,
presence_age_ms, sync_gap_ms, "suppressing push: active heuristic" if considered_active {
); trace!(
continue; ?user_id,
} presence_age_ms, sync_gap_ms, "suppressing push: active heuristic"
);
continue;
} }
} }

View File

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