Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

event_queue: Add compatibility code for push_device_registered_user_ids.

Prakhar Pratyushd78f3389166b
diff --git a/zerver/lib/notification_data.py b/zerver/lib/notification_data.py
index 0e66305125b..d37e470fa06 100644
--- a/zerver/lib/notification_data.py
+++ b/zerver/lib/notification_data.py
@@ -71,7 +71,7 @@ class UserMessageNotificationsData:
stream_wildcard_mention_in_followed_topic_user_ids: set[int],
muted_sender_user_ids: set[int],
all_bot_user_ids: set[int],
- push_device_registered_user_ids: set[int],
+ push_device_registered_user_ids: set[int] | None,
) -> "UserMessageNotificationsData":
if user_id in all_bot_user_ids:
# Don't send any notifications to bots
@@ -127,7 +127,17 @@ class UserMessageNotificationsData:
and "stream_wildcard_mentioned" in flags
)
- push_device_registered = user_id in push_device_registered_user_ids
+ # TODO/compatibility: `push_device_registered_user_ids` is None when
+ # `process_message_event`/`process_message_update_event` handles events
+ # prior to the introduction of `push_device_registered_user_ids` field in the events.
+ # We hardcode `push_device_registered` to True as the check is meant for newer events.
+ #
+ # Remove the `if` block when one can no longer directly upgrade from 11.x to main.
+ if push_device_registered_user_ids is None:
+ push_device_registered = True
+ else:
+ push_device_registered = user_id in push_device_registered_user_ids
+
dm_push_notify = (
push_device_registered
and user_id not in dm_mention_push_disabled_user_ids
diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py
index 8c5479170f5..974b409c6cc 100644
--- a/zerver/tornado/event_queue.py
+++ b/zerver/tornado/event_queue.py
@@ -1122,13 +1122,22 @@ def process_message_event(
)
muted_sender_user_ids = set(event_template.get("muted_sender_user_ids", []))
all_bot_user_ids = set(event_template.get("all_bot_user_ids", []))
- push_device_registered_user_ids = set(event_template.get("push_device_registered_user_ids", []))
disable_external_notifications = event_template.get("disable_external_notifications", False)
user_ids_without_access_to_sender = set(
event_template.get("user_ids_without_access_to_sender", [])
)
realm_host = event_template.get("realm_host", "")
+ # TODO/compatibility: We need to set `push_device_registered_user_ids` to None
+ # for message events prior to the introduction of `push_device_registered_user_ids`
+ # field in the event.
+ #
+ # Simplify this block to `push_device_registered_user_ids = set(event_template.get("push_device_registered_user_ids", []))`
+ # when one can no longer directly upgrade from 11.x to main.
+ push_device_registered_user_ids = event_template.get("push_device_registered_user_ids", None)
+ if push_device_registered_user_ids is not None:
+ push_device_registered_user_ids = set(push_device_registered_user_ids)
+
wide_dict: dict[str, Any] = event_template["message_dict"]
# Temporary transitional code: Zulip servers that have message
@@ -1403,13 +1412,22 @@ def process_message_update_event(
)
muted_sender_user_ids = set(event_template.pop("muted_sender_user_ids", []))
all_bot_user_ids = set(event_template.pop("all_bot_user_ids", []))
- push_device_registered_user_ids = set(event_template.pop("push_device_registered_user_ids", []))
disable_external_notifications = event_template.pop("disable_external_notifications", False)
online_push_user_ids = set(event_template.pop("online_push_user_ids", []))
stream_name = event_template.get("stream_name")
message_id = event_template["message_id"]
rendering_only_update = event_template["rendering_only"]
+ # TODO/compatibility: We need to set `push_device_registered_user_ids` to None
+ # for update_message events prior to the introduction of `push_device_registered_user_ids`
+ # field in the event.
+ #
+ # Simplify this block to `push_device_registered_user_ids = set(event_template.pop("push_device_registered_user_ids", []))`
+ # when one can no longer directly upgrade from 11.x to main.
+ push_device_registered_user_ids = event_template.pop("push_device_registered_user_ids", None)
+ if push_device_registered_user_ids is not None:
+ push_device_registered_user_ids = set(push_device_registered_user_ids)
+
for user_data in users:
user_profile_id = user_data["id"]