diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 65c3bdbb79..7682d106d0 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -1961,7 +1961,7 @@ def do_send_messages( dict( id=user_id, flags=user_flags.get(user_id, []), - always_push_notify=(user_id in send_request.online_push_user_ids), + online_push_enabled=(user_id in send_request.online_push_user_ids), stream_push_notify=(user_id in send_request.stream_push_user_ids), stream_email_notify=(user_id in send_request.stream_email_user_ids), wildcard_mention_notify=(user_id in send_request.wildcard_mention_user_ids), diff --git a/zerver/tests/test_event_queue.py b/zerver/tests/test_event_queue.py index fa5a2ab1bc..ce2d06ca27 100644 --- a/zerver/tests/test_event_queue.py +++ b/zerver/tests/test_event_queue.py @@ -63,7 +63,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -80,7 +80,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=True, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -98,7 +98,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={ "push_notified": True, @@ -117,7 +117,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={ "push_notified": False, @@ -137,7 +137,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -156,7 +156,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -173,7 +173,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=True, stream_email_notify=False, stream_name="Denmark", - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -190,7 +190,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=True, stream_name="Denmark", - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -207,7 +207,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=True, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=False, already_notified={}, ) @@ -224,7 +224,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=False, already_notified={}, ) @@ -241,14 +241,14 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name=None, - always_push_notify=False, + online_push_enabled=False, idle=False, already_notified={}, ) self.assertTrue(email_notice is None) self.assertTrue(mobile_notice is None) - # Private message sends push but not email if not idle but always_push_notify + # Private message sends push but not email if not idle but online_push_enabled email_notice, mobile_notice = self.check_will_notify( user_profile.id, message_id, @@ -258,14 +258,14 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=True, stream_name=None, - always_push_notify=True, + online_push_enabled=True, idle=False, already_notified={}, ) self.assertTrue(email_notice is None) self.assertTrue(mobile_notice is not None) - # Stream message sends push but not email if not idle but always_push_notify + # Stream message sends push but not email if not idle but online_push_enabled email_notice, mobile_notice = self.check_will_notify( user_profile.id, message_id, @@ -275,7 +275,7 @@ class MissedMessageNotificationsTest(ZulipTestCase): stream_push_notify=True, stream_email_notify=True, stream_name="Denmark", - always_push_notify=True, + online_push_enabled=True, idle=False, already_notified={}, ) diff --git a/zerver/tests/test_message_edit_notifications.py b/zerver/tests/test_message_edit_notifications.py index 694fb04e82..4adba48ebc 100644 --- a/zerver/tests/test_message_edit_notifications.py +++ b/zerver/tests/test_message_edit_notifications.py @@ -193,7 +193,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name="Scotland", - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -299,7 +299,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): present_on_web=True, ) - def test_always_push_notify_for_fully_present_mentioned_user(self) -> None: + def test_online_push_enabled_for_fully_present_mentioned_user(self) -> None: cordelia = self.example_user("cordelia") # Simulate Cordelia is FULLY present, not just in term of @@ -326,7 +326,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name="Scotland", - always_push_notify=True, + online_push_enabled=True, idle=False, already_notified={}, ) @@ -337,7 +337,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): self.assert_length(queue_messages, 1) - def test_always_push_notify_for_fully_present_boring_user(self) -> None: + def test_online_push_enabled_for_fully_present_boring_user(self) -> None: cordelia = self.example_user("cordelia") # Simulate Cordelia is FULLY present, not just in term of @@ -364,7 +364,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name="Scotland", - always_push_notify=True, + online_push_enabled=True, idle=False, already_notified={}, ) @@ -404,7 +404,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name="Scotland", - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -440,7 +440,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name="Scotland", - always_push_notify=False, + online_push_enabled=False, idle=True, already_notified={}, ) @@ -501,7 +501,7 @@ class EditMessageSideEffectsTest(ZulipTestCase): stream_push_notify=False, stream_email_notify=False, stream_name="Scotland", - always_push_notify=False, + online_push_enabled=False, idle=False, already_notified={}, ) diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index 8e7026d13b..9f925b8aa8 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -753,8 +753,8 @@ def missedmessage_hook( if not private_message: stream_name = event["message"]["display_recipient"] - # Since one is by definition idle, we don't need to check always_push_notify - always_push_notify = False + # Since one is by definition idle, we don't need to check online_push_enabled + online_push_enabled = False # Since we just GC'd the last event queue, the user is definitely idle. idle = True @@ -773,7 +773,7 @@ def missedmessage_hook( stream_push_notify, stream_email_notify, stream_name, - always_push_notify, + online_push_enabled, idle, already_notified, ) @@ -799,7 +799,7 @@ def maybe_enqueue_notifications( stream_push_notify: bool, stream_email_notify: bool, stream_name: Optional[str], - always_push_notify: bool, + online_push_enabled: bool, idle: bool, already_notified: Dict[str, bool], ) -> Dict[str, bool]: @@ -812,7 +812,7 @@ def maybe_enqueue_notifications( """ notified: Dict[str, bool] = {} - if (idle or always_push_notify) and ( + if (idle or online_push_enabled) and ( private_message or mentioned or wildcard_mention_notify or stream_push_notify ): notice = build_offline_notification(user_profile_id, message_id) @@ -968,7 +968,17 @@ def process_message_event( idle = receiver_is_off_zulip(user_profile_id) or ( user_profile_id in presence_idle_user_ids ) - always_push_notify = user_data.get("always_push_notify", False) + + # TODO/compatibility: Translation code for the rename of + # `always_push_notify` to `online_push_enabled`. Remove this + # when one can no longer directly upgrade from 4.x to master. + if "online_push_enabled" in user_data: + online_push_enabled = user_data["online_push_enabled"] + elif "always_push_notify" in user_data: + online_push_enabled = user_data["always_push_notify"] + else: + online_push_enabled = False + stream_name = event_template.get("stream_name") result: Dict[str, Any] = {} @@ -981,7 +991,7 @@ def process_message_event( stream_push_notify, stream_email_notify, stream_name, - always_push_notify, + online_push_enabled, idle, {}, ) @@ -1195,7 +1205,7 @@ def maybe_enqueue_notifications_for_message_update( # We can have newly mentioned people in an updated message. mentioned = user_profile_id in mention_user_ids - always_push_notify = user_profile_id in online_push_user_ids + online_push_enabled = user_profile_id in online_push_user_ids idle = (user_profile_id in presence_idle_user_ids) or receiver_is_off_zulip(user_profile_id) @@ -1208,7 +1218,7 @@ def maybe_enqueue_notifications_for_message_update( stream_push_notify=stream_push_notify, stream_email_notify=stream_email_notify, stream_name=stream_name, - always_push_notify=always_push_notify, + online_push_enabled=online_push_enabled, idle=idle, already_notified={}, )