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.

missedmessage_email: Fix missing '-group' decoration tag.

Prakhar Pratyush8556c5fcb033
diff --git a/zerver/lib/url_encoding.py b/zerver/lib/url_encoding.py
index 80bb3fffc10..8c8b3124e27 100644
--- a/zerver/lib/url_encoding.py
+++ b/zerver/lib/url_encoding.py
@@ -119,6 +119,13 @@ def direct_message_group_narrow_url(
# For group DMs with more than 2 users, we use other user IDs to create a slug.
other_user_ids = [r["id"] for r in display_recipient if r["id"] != user.id]
direct_message_slug = encode_user_ids(other_user_ids)
+
+ # `encode_user_ids` adds the decoration tag "-group" if length
+ # of the user_ids passed to it is 3 or more. `other_user_ids`
+ # has 1 less user ID, so we manually add the tag here.
+ if len(other_user_ids) == 2:
+ direct_message_slug += "-group"
+
base_url = f"{realm.url}/#narrow/dm/"
return base_url + direct_message_slug
diff --git a/zerver/tests/test_message_notification_emails.py b/zerver/tests/test_message_notification_emails.py
index 8cc3d41d6f2..d1fb60393fd 100644
--- a/zerver/tests/test_message_notification_emails.py
+++ b/zerver/tests/test_message_notification_emails.py
@@ -1309,6 +1309,26 @@ class TestMessageNotificationEmails(ZulipTestCase):
email_subject = "DMs with Cordelia, Lear's daughter"
self._test_cases(msg_id, verify_body_include, email_subject)
+ def test_group_dm_link_in_missed_message(self) -> None:
+ cordelia = self.example_user("cordelia")
+ hamlet = self.example_user("hamlet")
+ aaron = self.example_user("aaron")
+
+ msg_id = self.send_group_direct_message(
+ cordelia,
+ [hamlet, aaron, cordelia],
+ "Group DM link in email notifications",
+ )
+
+ other_users = sorted([aaron, cordelia], key=lambda user: user.id)
+ encoded_user_ids = ",".join([str(user.id) for user in other_users])
+ verify_body_include = [
+ f"view it in Zulip Dev Zulip: http://zulip.testserver/#narrow/dm/{encoded_user_ids}-group"
+ ]
+ group_display_name = " and ".join([user.full_name for user in other_users])
+ email_subject = "Group DMs with " + group_display_name
+ self._test_cases(msg_id, verify_body_include, email_subject)
+
def test_sender_name_in_missed_message(self) -> None:
hamlet = self.example_user("hamlet")
msg_id_1 = self.send_stream_message(