mirror of https://github.com/zulip/zulip.git
markdown: Use silent mentions in Notification Bot messages.
Messages converted: - new stream - rename stream - new user signup
This commit is contained in:
parent
f993fdd480
commit
988af1c803
|
@ -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.
|
||||
|
|
|
@ -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 = '<p><span class="user-mention" data-user-id="4">@King Hamlet</span> renamed stream <strong>old_name</strong> to <strong>stream with a brand new name</strong></p>'
|
||||
notification = '<p><span class="user-mention silent" data-user-id="4">@King Hamlet</span> renamed stream <strong>old_name</strong> to <strong>stream with a brand new name</strong></p>'
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = '<p>%s just created a new stream <a class="stream" data-stream-id="%d" href="/#narrow/stream/%s-%s">#%s</a>.</p>' % (
|
||||
user.full_name, stream_id, stream_id, invite_streams[0], invite_streams[0])
|
||||
expected_rendered_msg = '<p><span class="user-mention silent" data-user-id="%d">@%s</span> just created a new stream <a class="stream" data-stream-id="%d" href="/#narrow/stream/%s-%s">#%s</a>.</p>' % (
|
||||
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):
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue