From 29c2c8a3339d53813f94cd904bdb9db19696fc53 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 8 Sep 2025 20:19:41 +0000 Subject: [PATCH] Branch based on config to note sync for push suppression. Minor if-let condition and scope reduction; formatting. Signed-off-by: Jason Volk --- src/api/client/sync/v3.rs | 7 +++-- src/service/sending/sender.rs | 58 +++++++++++++++++------------------ tuwunel-example.toml | 4 +-- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/api/client/sync/v3.rs b/src/api/client/sync/v3.rs index 9759c7cb..e04de7ec 100644 --- a/src/api/client/sync/v3.rs +++ b/src/api/client/sync/v3.rs @@ -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 diff --git a/src/service/sending/sender.rs b/src/service/sending/sender.rs index 656c0ede..84759763 100644 --- a/src/service/sending/sender.rs +++ b/src/service/sending/sender.rs @@ -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; } } diff --git a/tuwunel-example.toml b/tuwunel-example.toml index e6f00ac8..6c709665 100644 --- a/tuwunel-example.toml +++ b/tuwunel-example.toml @@ -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) won’t receive push # notifications, reducing duplicate alerts while they're active -# elsewhere. +# on another client. # # Disabled by default to preserve legacy behavior. #