diff --git a/zerver/lib/notifications.py b/zerver/lib/notifications.py index 9e7dc57560..b32801f48d 100644 --- a/zerver/lib/notifications.py +++ b/zerver/lib/notifications.py @@ -11,7 +11,7 @@ from zerver.decorator import statsd_increment from zerver.lib.message import bulk_access_messages from zerver.lib.queue import queue_json_publish from zerver.lib.send_email import send_future_email, FromAddress -from zerver.lib.url_encoding import personal_narrow_url, pm_narrow_url, \ +from zerver.lib.url_encoding import personal_narrow_url, huddle_narrow_url, \ stream_narrow_url, topic_narrow_url from zerver.models import ( Recipient, @@ -178,10 +178,15 @@ def build_message_list(user_profile: UserProfile, messages: List[Message]) -> Li disp_recipient = get_display_recipient(message.recipient) assert not isinstance(disp_recipient, str) other_recipients = [r['full_name'] for r in disp_recipient - if r['email'] != user_profile.email] + if r['id'] != user_profile.id] header = "You and %s" % (", ".join(other_recipients),) - html_link = pm_narrow_url(user_profile.realm, [r["email"] for r in disp_recipient - if r["email"] != user_profile.email]) + other_user_ids = [r['id'] for r in disp_recipient + if r['id'] != user_profile.id] + html_link = huddle_narrow_url( + realm=user_profile.realm, + other_user_ids=other_user_ids, + ) + header_html = "%s" % (html_link, header) else: stream = Stream.objects.only('id', 'name').get(id=message.recipient.type_id) diff --git a/zerver/lib/url_encoding.py b/zerver/lib/url_encoding.py index f736ef0b07..20778e63d9 100644 --- a/zerver/lib/url_encoding.py +++ b/zerver/lib/url_encoding.py @@ -21,10 +21,10 @@ def personal_narrow_url(realm: Realm, sender: UserProfile) -> str: pm_slug = str(sender.id) + '-' + hash_util_encode(email_user) return base_url + pm_slug -def pm_narrow_url(realm: Realm, participants: List[str]) -> str: - participants.sort() +def huddle_narrow_url(realm: Realm, other_user_ids: List[int]) -> str: + pm_slug = ','.join(str(user_id) for user_id in sorted(other_user_ids)) + '-group' base_url = "%s/#narrow/pm-with/" % (realm.uri,) - return base_url + hash_util_encode(",".join(participants)) + return base_url + pm_slug def stream_narrow_url(realm: Realm, stream: Stream) -> str: base_url = "%s/#narrow/stream/" % (realm.uri,) diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py index f718fcb29c..16c3d26d54 100644 --- a/zerver/tests/test_digest.py +++ b/zerver/tests/test_digest.py @@ -74,7 +74,14 @@ class TestDigestEmailMessages(ZulipTestCase): kwargs = mock_send_future_email.call_args[1] self.assertEqual(kwargs['to_user_id'], user_profile.id) html = kwargs['context']['unread_pms'][0]['header']['html'] - self.assertIn("'http://zulip.testserver/#narrow/pm-with/cordelia.40zulip.2Ecom.2Chamlet.40zulip.2Ecom'", html) + + other_user_ids = sorted([ + self.example_user('cordelia').id, + self.example_user('hamlet').id, + ]) + slug = ','.join(str(user_id) for user_id in other_user_ids) + '-group' + expected_url = "'http://zulip.testserver/#narrow/pm-with/" + slug + "'" + self.assertIn(expected_url, html) @mock.patch('zerver.lib.digest.queue_digest_recipient') @mock.patch('zerver.lib.digest.timezone_now')