mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
Send missedmessage notifications as soon as you're idle or offline
Previously, you'd have to be offline to recieve missedmessage notifications, or maybe idle for an hour. However, I'm pretty sure the latter code didn't actually work, so we scrap that and just nofity you via email or push as soon as you're idle. Closes trac #2350 (imported from commit 899966e0514db575b9640a96865639201824b579)
This commit is contained in:
committed by
Leo Franchi
parent
5bb4a74ec0
commit
bba2eb7622
@@ -78,23 +78,28 @@ def receiver_is_idle(user_profile_id, realm_presences):
|
||||
if realm_presences is None or not user_profile_id in realm_presences:
|
||||
return off_zulip
|
||||
|
||||
# If the most recent online status from a user is >1hr in the past, we notify
|
||||
# them regardless of whether or not they have an open window
|
||||
# We want to find the newest "active" presence entity and compare that to the
|
||||
# activity expiry threshold.
|
||||
user_presence = realm_presences[user_profile_id]
|
||||
idle_too_long = False
|
||||
newest = None
|
||||
latest_active_timestamp = None
|
||||
idle = False
|
||||
|
||||
for client, status in user_presence.iteritems():
|
||||
if newest is None or status['timestamp'] > newest['timestamp']:
|
||||
newest = status
|
||||
if (latest_active_timestamp is None or status['timestamp'] > latest_active_timestamp) and \
|
||||
status['status'] == 'active':
|
||||
latest_active_timestamp = status['timestamp']
|
||||
|
||||
update_time = timestamp_to_datetime(newest['timestamp'])
|
||||
if now() - update_time > datetime.timedelta(hours=NOTIFY_AFTER_IDLE_HOURS):
|
||||
idle_too_long = True
|
||||
if latest_active_timestamp is None:
|
||||
idle = True
|
||||
else:
|
||||
active_datetime = timestamp_to_datetime(latest_active_timestamp)
|
||||
# 140 seconds is consistent with activity.js:OFFLINE_THRESHOLD_SECS
|
||||
idle = now() - active_datetime > datetime.timedelta(seconds=140)
|
||||
|
||||
return off_zulip or idle_too_long
|
||||
return off_zulip or idle
|
||||
|
||||
def process_message_event(event_template, users):
|
||||
realm_presences = event_template['presences']
|
||||
realm_presences = {int(k): v for k, v in event_template['presences'].items()}
|
||||
sender_queue_id = event_template.get('sender_queue_id', None)
|
||||
if "message_dict_markdown" in event_template:
|
||||
message_dict_markdown = event_template['message_dict_markdown']
|
||||
|
||||
Reference in New Issue
Block a user