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.
This commit is contained in:
Mateusz Mandera 2023-02-18 21:19:57 +01:00 committed by Tim Abbott
parent 38b7ecff68
commit 4ba4305ff9
2 changed files with 3 additions and 8 deletions

View File

@ -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,

View File

@ -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.