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:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) won’t receive push
|
# (based on presence state and sync activity) won’t 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.
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user