initial_state_data: Add support for empty topic name.

This commit is a part of the work to support empty string
as a topic name.

Previously, empty string was not a valid topic name.

Adds backward compatibility for topic names in `user_topics`
objects returned in `/register` response.
This commit is contained in:
Prakhar Pratyush
2024-12-02 18:11:23 +05:30
committed by Tim Abbott
parent 1a83c23c83
commit 1d1431297c
4 changed files with 41 additions and 4 deletions

View File

@@ -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
)