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: Remove pre-5.0 compatibility code.

Tim Abbottbc017d339479
diff --git a/zerver/tests/test_event_queue.py b/zerver/tests/test_event_queue.py
index 21cc48f8c7a..c856a46e081 100644
--- a/zerver/tests/test_event_queue.py
+++ b/zerver/tests/test_event_queue.py
@@ -25,7 +25,6 @@ from zerver.tornado.event_queue import (
maybe_enqueue_notifications,
missedmessage_hook,
persistent_queue_filename,
- process_notification,
)
from zerver.tornado.views import cleanup_event_queue, get_events
@@ -1505,67 +1504,3 @@ class EventQueueTest(ZulipTestCase):
queue.prune(1)
self.verify_to_dict_end_to_end(client)
-
-
-class SchemaMigrationsTests(ZulipTestCase):
- def test_reformat_legacy_send_message_event(self) -> None:
- hamlet = self.example_user("hamlet")
- cordelia = self.example_user("cordelia")
- othello = self.example_user("othello")
- old_format_event = dict(
- type="message",
- message=1,
- message_dict={},
- presence_idle_user_ids=[hamlet.id, othello.id],
- )
- old_format_users = [
- dict(
- id=hamlet.id,
- flags=["mentioned"],
- mentioned=True,
- online_push_enabled=True,
- stream_push_notify=False,
- stream_email_notify=True,
- wildcard_mention_notify=False,
- sender_is_muted=False,
- ),
- dict(
- id=cordelia.id,
- flags=["stream_wildcard_mentioned"],
- mentioned=False,
- online_push_enabled=True,
- stream_push_notify=True,
- stream_email_notify=False,
- wildcard_mention_notify=True,
- sender_is_muted=False,
- ),
- ]
- notice = dict(event=old_format_event, users=old_format_users)
-
- expected_current_format_users = [
- dict(
- id=hamlet.id,
- flags=["mentioned"],
- ),
- dict(
- id=cordelia.id,
- flags=["stream_wildcard_mentioned"],
- ),
- ]
-
- expected_current_format_event = dict(
- type="message",
- message=1,
- message_dict={},
- presence_idle_user_ids=[hamlet.id, othello.id],
- online_push_user_ids=[hamlet.id, cordelia.id],
- stream_push_user_ids=[cordelia.id],
- stream_email_user_ids=[hamlet.id],
- stream_wildcard_mention_user_ids=[cordelia.id],
- muted_sender_user_ids=[],
- )
- with mock.patch("zerver.tornado.event_queue.process_message_event") as m:
- process_notification(notice)
- m.assert_called_once()
- self.assertDictEqual(m.call_args[0][0], expected_current_format_event)
- self.assertEqual(m.call_args[0][1], expected_current_format_users)
diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py
index 1339135f2e5..1f0018d1024 100644
--- a/zerver/tornado/event_queue.py
+++ b/zerver/tornado/event_queue.py
@@ -1381,31 +1381,10 @@ 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", []))
disable_external_notifications = event_template.pop("disable_external_notifications", False)
-
- # TODO/compatibility: Translation code for the rename of
- # `push_notify_user_ids` to `online_push_user_ids`. Remove this
- # when one can no longer directly upgrade from 4.x to main.
- online_push_user_ids = set()
- if "online_push_user_ids" in event_template:
- online_push_user_ids = set(event_template.pop("online_push_user_ids"))
- elif "push_notify_user_ids" in event_template:
- online_push_user_ids = set(event_template.pop("push_notify_user_ids"))
-
+ 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"]
-
- # TODO/compatibility: Modern `update_message` events contain the
- # rendering_only key, which indicates whether the update is a link
- # preview rendering update (not a human action). However, because
- # events may be in the notify_tornado queue at the time we
- # upgrade, we need the below logic to compute rendering_only based
- # on the `user_id` key not being present in legacy events that
- # would have had rendering_only set. Remove this check when one
- # can no longer directly update from 4.x to main.
- if "rendering_only" in event_template:
- rendering_only_update = event_template["rendering_only"]
- else:
- rendering_only_update = "user_id" not in event_template
+ rendering_only_update = event_template["rendering_only"]
for user_data in users:
user_profile_id = user_data["id"]
@@ -1565,50 +1544,6 @@ def maybe_enqueue_notifications_for_message_update(
)
-def reformat_legacy_send_message_event(
- event: Mapping[str, Any], users: list[int] | list[Mapping[str, Any]]
-) -> tuple[MutableMapping[str, Any], Collection[MutableMapping[str, Any]]]:
- # do_send_messages used to send events with users in dict format, with the
- # dict containing the user_id and other data. We later trimmed down the user
- # data to only contain the user_id and the usermessage flags, and put everything
- # else in the event dict as lists.
- # This block handles any old-format events still in the queue during upgrade.
-
- modern_event = cast(MutableMapping[str, Any], event)
- user_dicts = cast(list[MutableMapping[str, Any]], users)
-
- # Back-calculate the older all-booleans format data in the `users` dicts into the newer
- # all-lists format, and attach the lists to the `event` object.
- modern_event["online_push_user_ids"] = []
- modern_event["stream_push_user_ids"] = []
- modern_event["stream_email_user_ids"] = []
- modern_event["stream_wildcard_mention_user_ids"] = []
- modern_event["muted_sender_user_ids"] = []
-
- for user in user_dicts:
- user_id = user["id"]
-
- if user.pop("stream_push_notify", False):
- modern_event["stream_push_user_ids"].append(user_id)
- if user.pop("stream_email_notify", False):
- modern_event["stream_email_user_ids"].append(user_id)
- if user.pop("wildcard_mention_notify", False):
- modern_event["stream_wildcard_mention_user_ids"].append(user_id)
- if user.pop("sender_is_muted", False):
- modern_event["muted_sender_user_ids"].append(user_id)
-
- # TODO/compatibility: Another translation code block for the rename of
- # `always_push_notify` to `online_push_enabled`. Remove this
- # when one can no longer directly upgrade from 4.x to 5.0-dev.
- if user.pop("online_push_enabled", False) or user.pop("always_push_notify", False):
- modern_event["online_push_user_ids"].append(user_id)
-
- # We can calculate `mentioned` from the usermessage flags, so just remove it
- user.pop("mentioned", False)
-
- return (modern_event, user_dicts)
-
-
def process_user_group_name_update_event(event: Mapping[str, Any], users: Iterable[int]) -> None:
user_group_event = dict(event)
# 'deactivated' field is no longer needed and can be popped, as we now
@@ -1689,13 +1624,7 @@ def process_notification(notice: Mapping[str, Any]) -> None:
start_time = time.perf_counter()
if event["type"] == "message":
- if len(users) > 0 and isinstance(users[0], dict) and "stream_push_notify" in users[0]:
- # TODO/compatibility: Remove this whole block once one can no
- # longer directly upgrade directly from 4.x to 5.0-dev.
- modern_event, user_dicts = reformat_legacy_send_message_event(event, users)
- process_message_event(modern_event, user_dicts)
- else:
- process_message_event(event, cast(list[Mapping[str, Any]], users))
+ process_message_event(event, cast(list[Mapping[str, Any]], users))
elif event["type"] == "update_message":
process_message_update_event(event, cast(list[Mapping[str, Any]], users))
elif event["type"] == "delete_message":