From 4ba4305ff9f438bb580a6fa4108e1747290d00c1 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sat, 18 Feb 2023 21:19:57 +0100 Subject: [PATCH] presence: Change server-side OFFLINE_THRESHOLD_SECS to 140s. This old 300s value was meaningfully used in 2 places: 1. In the do_change_user_settings presence_enabled codepath when turning a user invisible. It doesn't matter there, 140s is just since the point is to make clients see this user as offline. And 140s is the threshold used by clients (see the presence.js constant). 2. For calculating whether to set "offline" "status" in result["presence"]["aggregated"] in get_presence_backend. It's fine for this to become 140s, since clients shouldn't be looking at the status value anymore anyway and just do their calculation based on the timestamps. --- zerver/actions/message_send.py | 5 +---- zproject/default_settings.py | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py index 45d3d8ed01..6b62928dbd 100644 --- a/zerver/actions/message_send.py +++ b/zerver/actions/message_send.py @@ -696,10 +696,7 @@ def filter_presence_idle_user_ids(user_ids: Set[int]) -> List[int]: if not user_ids: return [] - # Matches presence.js constant - OFFLINE_THRESHOLD_SECS = 140 - - recent = timezone_now() - datetime.timedelta(seconds=OFFLINE_THRESHOLD_SECS) + recent = timezone_now() - datetime.timedelta(seconds=settings.OFFLINE_THRESHOLD_SECS) rows = ( UserPresence.objects.filter( user_profile_id__in=user_ids, diff --git a/zproject/default_settings.py b/zproject/default_settings.py index 1e2c7a3f5d..0894ffe2a1 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -488,10 +488,8 @@ LOG_API_EVENT_TYPES = False STAGING = False # How long to wait before presence should treat a user as offline. -# TODO: Figure out why this is different from the corresponding -# value in static/js/presence.js. Also, probably move it out of -# default_settings, since it likely isn't usefully user-configurable. -OFFLINE_THRESHOLD_SECS = 5 * 60 +# Should match the presence.js constant. +OFFLINE_THRESHOLD_SECS = 140 # Specifies the number of active users in the realm # above which sending of presence update events will be disabled.