Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
initial_state_data: Add support for empty topic name.
Prakhar Pratyush1d1431297ce8
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex 2be3e2dfca0..f50ebb5788f 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -56,8 +56,9 @@ format used by the Zulip server that they are interacting with.* [`POST /register`](/api/register-queue): For clients that don't supportthe `empty_topic_name` [client capability](/api/register-queue#parameter-client_capabilities),- the `topic` field in the `unread_msgs` object will have the value- of `realm_empty_topic_display_name` field replacing the empty string+ the `topic` field in the `unread_msgs` object and `topic_name` field+ in the `user_topics` objects will have the value of+ `realm_empty_topic_display_name` field replacing the empty stringfor channel messages.**Feature level 333**diff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex 8632f642369..a56787e0e6a 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -59,7 +59,7 @@ from zerver.lib.subscription_info import (from zerver.lib.thumbnail import THUMBNAIL_OUTPUT_FORMATSfrom zerver.lib.timestamp import datetime_to_timestampfrom zerver.lib.timezone import canonicalize_timezone-from zerver.lib.topic import TOPIC_NAME+from zerver.lib.topic import TOPIC_NAME, maybe_rename_general_chat_to_empty_topicfrom zerver.lib.user_groups import (get_group_setting_value_for_api,get_recursive_membership_groups,@@ -1712,9 +1712,10 @@ def apply_event(if event["visibility_policy"] == UserTopic.VisibilityPolicy.INHERIT:user_topics_state = state["user_topics"]for i in range(len(user_topics_state)):+ topic_name = maybe_rename_general_chat_to_empty_topic(event["topic_name"])if (user_topics_state[i]["stream_id"] == event["stream_id"]- and user_topics_state[i]["topic_name"] == event["topic_name"]+ and user_topics_state[i]["topic_name"] == topic_name):del user_topics_state[i]break@@ -1988,3 +1989,8 @@ def post_process_state(handle_stream_notifications_compatibility(user_profile, stream_dict, notification_settings_null)++ if not allow_empty_topic_name and "user_topics" in ret:+ for user_topic in ret["user_topics"]:+ if user_topic["topic_name"] == "":+ user_topic["topic_name"] = Message.EMPTY_TOPIC_FALLBACK_NAMEdiff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 87caf1eb1ae..40f70f6c09b 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -15780,6 +15780,15 @@ paths:type: stringdescription: |The name of the topic.++ Note that the empty string topic may have been rewritten by the server to+ the value of `realm_empty_topic_display_name` found in the [`POST /register`](/api/register-queue)+ response depending on the value of the `empty_topic_name` [client capability][client-capabilities].++ **Changes**: The `empty_topic_name` client capability is new in+ Zulip 10.0 (feature level 334).++ [client-capabilities]: /api/register-queue#parameter-client_capabilitieslast_updated:type: integerdescription: |diff --git a/zerver/tests/test_message_topics.py b/zerver/tests/test_message_topics.pyindex 21b0f1d9871..e62fc532ef4 100644--- a/zerver/tests/test_message_topics.py+++ b/zerver/tests/test_message_topics.py@@ -795,6 +795,19 @@ class EmptyTopicNameTest(ZulipTestCase):self.send_stream_message(hamlet, "Denmark", topic_name="")self.send_stream_message(hamlet, "Verona", topic_name=Message.EMPTY_TOPIC_FALLBACK_NAME)+ do_set_user_topic_visibility_policy(+ iago,+ get_stream("Denmark", iago.realm),+ "",+ visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,+ )+ do_set_user_topic_visibility_policy(+ iago,+ get_stream("Verona", iago.realm),+ Message.EMPTY_TOPIC_FALLBACK_NAME,+ visibility_policy=UserTopic.VisibilityPolicy.UNMUTED,+ )+with mock.patch("zerver.lib.events.request_event_queue", return_value=1):state_data = do_events_register(iago,@@ -806,6 +819,8 @@ class EmptyTopicNameTest(ZulipTestCase):)self.assertEqual(state_data["unread_msgs"]["streams"][0]["topic"], "")self.assertEqual(state_data["unread_msgs"]["streams"][1]["topic"], "")+ self.assertEqual(state_data["user_topics"][0]["topic_name"], "")+ self.assertEqual(state_data["user_topics"][1]["topic_name"], "")with mock.patch("zerver.lib.events.request_event_queue", return_value=1):state_data = do_events_register(@@ -822,3 +837,9 @@ class EmptyTopicNameTest(ZulipTestCase):self.assertEqual(state_data["unread_msgs"]["streams"][1]["topic"], Message.EMPTY_TOPIC_FALLBACK_NAME)+ self.assertEqual(+ state_data["user_topics"][0]["topic_name"], Message.EMPTY_TOPIC_FALLBACK_NAME+ )+ self.assertEqual(+ state_data["user_topics"][1]["topic_name"], Message.EMPTY_TOPIC_FALLBACK_NAME+ )