diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 42f14998db..0a02fc487a 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -252,8 +252,8 @@ def send_signup_message(sender: UserProfile, admin_realm_signup_notifications_st "stream", signup_notifications_stream.name, "signups", - "%s (%s) just signed up for Zulip. (total: %i)" % ( - user_profile.full_name, user_profile.email, user_count + "_@**%s|%s** just signed up for Zulip. (total: %i)" % ( + user_profile.full_name, user_profile.id, user_count ) ) @@ -3356,7 +3356,9 @@ def do_rename_stream(stream: Stream, sender, new_name, "welcome", - "@**%s** renamed stream **%s** to **%s**" % (user_profile.full_name, old_name, new_name) + "_@**%s|%d** renamed stream **%s** to **%s**" % (user_profile.full_name, + user_profile.id, + old_name, new_name) ) # Even though the token doesn't change, the web client needs to update the # email forwarding address to display the correctly-escaped new name. diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index ee2ff2ac54..74ebd95c1c 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -2094,7 +2094,7 @@ class EventsRegisterTest(ZulipTestCase): stream = self.make_stream('old_name') new_name = u'stream with a brand new name' self.subscribe(self.user_profile, stream.name) - notification = '

@King Hamlet renamed stream old_name to stream with a brand new name

' + notification = '

@King Hamlet renamed stream old_name to stream with a brand new name

' action = lambda: do_rename_stream(stream, new_name, self.user_profile) events = self.do_test(action, num_events=3) schema_checker = self.check_events_dict([ @@ -2118,9 +2118,7 @@ class EventsRegisterTest(ZulipTestCase): error = schema_checker('events[1]', events[1]) self.assert_on_error(error) schema_checker = check_dict([ - ('stream_email_notify', equals(False)), ('flags', check_list(check_string)), - ('email_notified', equals(True)), ('type', equals('message')), ('message', check_dict([ ('timestamp', check_int), @@ -2144,9 +2142,7 @@ class EventsRegisterTest(ZulipTestCase): (TOPIC_NAME, equals('welcome')), ('recipient_id', check_int) ])), - ('id', check_int), - ('push_notified', equals(True)), - ('stream_push_notify', equals(False)), + ('id', check_int) ]) error = schema_checker('events[2]', events[2]) self.assert_on_error(error) diff --git a/zerver/tests/test_new_users.py b/zerver/tests/test_new_users.py index 897e924df8..580f5e59e3 100644 --- a/zerver/tests/test_new_users.py +++ b/zerver/tests/test_new_users.py @@ -194,3 +194,4 @@ class TestNotifyNewUser(ZulipTestCase): self.assertEqual(message.recipient.type, Recipient.STREAM) actual_stream = Stream.objects.get(id=message.recipient.type_id) self.assertEqual(actual_stream.name, Realm.INITIAL_PRIVATE_STREAM_NAME) + self.assertIn('_@**Cordelia Lear|%d** just signed up for Zulip.' % (new_user.id), message.content) diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 5eb1021dbf..81c961a858 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -621,7 +621,7 @@ class StreamAdminTest(ZulipTestCase): # Inspect the notification message sent message = self.get_last_message() actual_stream = Stream.objects.get(id=message.recipient.type_id) - message_content = '@**King Hamlet** renamed stream **stream_name1** to **stream_name2**' + message_content = '_@**King Hamlet|{}** renamed stream **stream_name1** to **stream_name2**'.format(user_profile.id) self.assertEqual(message.sender.realm, user_profile.realm) self.assertEqual(actual_stream.name, 'stream_name2') self.assertEqual(message.recipient.type, Recipient.STREAM) @@ -1921,6 +1921,7 @@ class SubscriptionAPITest(ZulipTestCase): """ invitee = self.example_email("iago") invitee_full_name = 'Iago' + invitee_user = self.example_user('iago') current_stream = self.get_streams(invitee, self.test_realm)[0] invite_streams = self.make_random_stream_names([current_stream])[:1] @@ -1946,7 +1947,7 @@ class SubscriptionAPITest(ZulipTestCase): msg = self.get_second_to_last_message() self.assertEqual(msg.recipient.type, Recipient.STREAM) self.assertEqual(msg.sender_id, self.notification_bot().id) - expected_msg = "%s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0]) + expected_msg = "_@**%s|%d** just created a new stream #**%s**." % (invitee_full_name, invitee_user.id, invite_streams[0]) self.assertEqual(msg.content, expected_msg) def test_successful_cross_realm_notification(self) -> None: @@ -1984,8 +1985,8 @@ class SubscriptionAPITest(ZulipTestCase): self.assertEqual(msg.recipient.type, Recipient.STREAM) self.assertEqual(msg.sender_id, self.notification_bot().id) stream_id = Stream.objects.latest('id').id - expected_rendered_msg = '

%s just created a new stream #%s.

' % ( - user.full_name, stream_id, stream_id, invite_streams[0], invite_streams[0]) + expected_rendered_msg = '

@%s just created a new stream #%s.

' % ( + user.id, user.full_name, stream_id, stream_id, invite_streams[0], invite_streams[0]) self.assertEqual(msg.rendered_content, expected_rendered_msg) def test_successful_subscriptions_notifies_with_escaping(self) -> None: @@ -1994,6 +1995,7 @@ class SubscriptionAPITest(ZulipTestCase): """ invitee = self.example_email("iago") invitee_full_name = 'Iago' + invitee_user = self.example_user('iago') current_stream = self.get_streams(invitee, self.test_realm)[0] notifications_stream = get_stream(current_stream, self.test_realm) @@ -2013,7 +2015,7 @@ class SubscriptionAPITest(ZulipTestCase): msg = self.get_second_to_last_message() self.assertEqual(msg.sender_id, self.notification_bot().id) - expected_msg = "%s just created a new stream #**%s**." % (invitee_full_name, invite_streams[0]) + expected_msg = "_@**%s|%d** just created a new stream #**%s**." % (invitee_full_name, invitee_user.id, invite_streams[0]) self.assertEqual(msg.content, expected_msg) def test_non_ascii_stream_subscription(self) -> None: @@ -2928,7 +2930,7 @@ class SubscriptionAPITest(ZulipTestCase): principals=ujson.dumps([user1.email, user2.email]) ) ) - self.assert_length(queries, 52) + self.assert_length(queries, 53) class GetPublicStreamsTest(ZulipTestCase): diff --git a/zerver/views/streams.py b/zerver/views/streams.py index 6dfcbdab6d..b7fff36849 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -378,7 +378,7 @@ def add_subscriptions_backend( stream_msg = "the following streams: %s" % (stream_strs,) else: stream_msg = "a new stream #**%s**." % created_streams[0].name - msg = ("%s just created %s" % (user_profile.full_name, stream_msg)) + msg = ("_@**%s|%d** just created %s" % (user_profile.full_name, user_profile.id, stream_msg)) sender = get_system_bot(settings.NOTIFICATION_BOT) stream_name = notifications_stream.name