mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 16:14:02 +00:00
event_queue: Add compatibility code for push_device_registered_user_ids.
In #35965 we added `push_device_registered_user_ids` to message & update_message event. Zulip servers with such events in their event queues when upgraded to the new version set push_device_registered_user_ids to empty list, which is incorrect - it leads to no push notification sent. This commit adds compatibility code to handle such events. The newly introduced `push_device_registered` check is used only for events with `push_device_registered_user_id` present in them.
This commit is contained in:
committed by
Tim Abbott
parent
3c2ed0e202
commit
d78f338916
@@ -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
|
||||
|
@@ -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"]
|
||||
|
||||
|
Reference in New Issue
Block a user