Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
user_topics events: Use MutedTopicsEvent and UserTopicEvent.
Evy Kassirerb159e07c4db6
diff --git a/zerver/actions/user_topics.py b/zerver/actions/user_topics.pyindex 90468789085..b1509500267 100644--- a/zerver/actions/user_topics.py+++ b/zerver/actions/user_topics.py@@ -1,9 +1,9 @@from datetime import datetime-from typing import Anyfrom django.db import transactionfrom django.utils.timezone import now as timezone_now+from zerver.lib.event_types import MutedTopicsEvent, UserTopicEventfrom zerver.lib.timestamp import datetime_to_timestampfrom zerver.lib.topic import maybe_rename_general_chat_to_empty_topicfrom zerver.lib.user_topics import (@@ -49,19 +49,15 @@ def bulk_do_set_user_topic_visibility_policy(# once clients are migrated to handle the user_topic event type# instead.if not skip_muted_topics_event:- muted_topics_event = dict(- type="muted_topics", muted_topics=get_topic_mutes(user_profile)- )+ muted_topics_event = MutedTopicsEvent(muted_topics=get_topic_mutes(user_profile))send_event_on_commit(user_profile.realm, muted_topics_event, [user_profile.id])- user_topic_event: dict[str, Any] = {- "type": "user_topic",- "stream_id": stream.id,- "topic_name": topic_name,- "last_updated": datetime_to_timestamp(last_updated),- "visibility_policy": visibility_policy,- }-+ user_topic_event = UserTopicEvent(+ stream_id=stream.id,+ topic_name=topic_name,+ last_updated=datetime_to_timestamp(last_updated),+ visibility_policy=visibility_policy,+ )send_event_on_commit(user_profile.realm, user_topic_event, [user_profile.id])diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.pyindex 5d73ea99831..671b8e870dd 100644--- a/zerver/lib/event_types.py+++ b/zerver/lib/event_types.py@@ -268,7 +268,7 @@ class MessageEvent(BaseEvent):class MutedTopicsEvent(BaseEvent):- type: Literal["muted_topics"]+ type: Literal["muted_topics"] = "muted_topics"muted_topics: list[list[str | int]]@@ -1270,7 +1270,7 @@ class UserStatusEvent(UserStatusCoreEvent):class UserTopicEvent(BaseEvent):- type: Literal["user_topic"]+ type: Literal["user_topic"] = "user_topic"stream_id: inttopic_name: strlast_updated: intdiff --git a/zerver/tests/test_message_move_topic.py b/zerver/tests/test_message_move_topic.pyindex 85cb45612ef..30687d24ee6 100644--- a/zerver/tests/test_message_move_topic.py+++ b/zerver/tests/test_message_move_topic.py@@ -464,13 +464,13 @@ class MessageMoveTopicTest(ZulipTestCase):for call_args in mock_send_event_on_commit.call_args_list:(_arg_realm, arg_event, arg_notified_users) = call_args[0][notified_user_id] = arg_notified_users- if arg_event["type"] == "user_topic":- self.assertEqual(arg_event["stream_id"], stream.id)+ if arg_event.type == "user_topic":+ self.assertEqual(arg_event.stream_id, stream.id)user_topic_events[notified_user_id].append(- (arg_event["topic_name"], arg_event["visibility_policy"])+ (arg_event.topic_name, arg_event.visibility_policy))- elif arg_event["type"] == "muted_topics":- muted_topics_events[notified_user_id].append(arg_event["muted_topics"])+ elif arg_event.type == "muted_topics":+ muted_topics_events[notified_user_id].append(arg_event.muted_topics)self.assertEqual(user_topic_events[hamlet.id],[@@ -597,9 +597,9 @@ class MessageMoveTopicTest(ZulipTestCase):users_notified_via_user_topic_event: list[int] = []for call_args in mock_send_event_on_commit.call_args_list:(_arg_realm, arg_event, arg_notified_users) = call_args[0]- if arg_event["type"] == "user_topic":+ if arg_event.type == "user_topic":users_notified_via_user_topic_event.append(*arg_notified_users)- elif arg_event["type"] == "muted_topics":+ elif arg_event.type == "muted_topics":users_notified_via_muted_topics_event.append(*arg_notified_users)self.assertEqual(sorted(users_notified_via_muted_topics_event),@@ -859,9 +859,9 @@ class MessageMoveTopicTest(ZulipTestCase):users_notified_via_user_topic_event: list[int] = []for call_args in mock_send_event_on_commit.call_args_list:(_arg_realm, arg_event, arg_notified_users) = call_args[0]- if arg_event["type"] == "user_topic":+ if arg_event.type == "user_topic":users_notified_via_user_topic_event.append(*arg_notified_users)- elif arg_event["type"] == "muted_topics":+ elif arg_event.type == "muted_topics":users_notified_via_muted_topics_event.append(*arg_notified_users)self.assertEqual(sorted(users_notified_via_muted_topics_event),