From e6bb683922b9713a1ac91567ddbd51bfea6b5955 Mon Sep 17 00:00:00 2001 From: Luke Faraone Date: Mon, 17 Mar 2014 13:35:43 -0400 Subject: [PATCH] Suppress presence changes to IDLE until timeout This way if two browsers are disagreeing about your active status, the active one wins. The active browser continues to update your timestamp, and the idle browser's changes are discarded until the timestamp on your active status expires. (imported from commit dc29e013d045c4b72793097f611ba6802c58e57a) --- zerver/lib/actions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 82935e81e1..8a9f5d4991 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -1788,7 +1788,13 @@ def do_update_user_presence(user_profile, client, log_time, status): was_idle = presence.status == UserPresence.IDLE became_online = (status == UserPresence.ACTIVE) and (stale_status or was_idle) - if not created: + # If an object was created, it has already been saved. + # + # We suppress changes from ACTIVE to IDLE before stale_status is reached; + # this protects us from the user having two clients open: one active, the + # other idle. Without this check, we would constantly toggle their status + # between the two states. + if not created and stale_status or was_idle or status == presence.status: # The following block attempts to only update the "status" # field in the event that it actually changed. This is # important to avoid flushing the UserPresence cache when the