markdown: Change syntax of silent mentions ( _@person -> @_person).

This commit is contained in:
Rohitt Vashishtha 2019-02-20 09:15:33 +00:00 committed by Tim Abbott
parent cdce66813e
commit 57b9991396
10 changed files with 15 additions and 15 deletions

View File

@ -61,7 +61,7 @@ in bursts.
- Added a ReviewBoard integration, and improved numerous existing integrations. - Added a ReviewBoard integration, and improved numerous existing integrations.
- Added support for multi-line messages for the /me feature. - Added support for multi-line messages for the /me feature.
- Added markdown rendering of text when displaying custom profile fields. - Added markdown rendering of text when displaying custom profile fields.
- Added "silent mentions" syntax (`_@**Tim Abbott**`), which show - Added "silent mentions" syntax (`@_**Tim Abbott**`), which show
visually, but don't trigger a notification to the target user. visually, but don't trigger a notification to the target user.
- Added support for using lightbox in compose preview. - Added support for using lightbox in compose preview.
- Changes in date no longer force a repeated recipient bar. This - Changes in date no longer force a repeated recipient bar. This

View File

@ -302,7 +302,7 @@ run_test('marked', () => {
expected: '<p><span aria-label="poop" class="emoji emoji-1f4a9" role="img" title="poop">:poop:</span></p>'}, expected: '<p><span aria-label="poop" class="emoji emoji-1f4a9" role="img" title="poop">:poop:</span></p>'},
{input: '\u{1f6b2}', {input: '\u{1f6b2}',
expected: '<p>\u{1f6b2}</p>' }, expected: '<p>\u{1f6b2}</p>' },
{input: 'Silent mention: _@**Cordelia Lear**', {input: 'Silent mention: @_**Cordelia Lear**',
expected: '<p>Silent mention: <span class="user-mention silent" data-user-id="101">@Cordelia Lear</span></p>'}, expected: '<p>Silent mention: <span class="user-mention silent" data-user-id="101">@Cordelia Lear</span></p>'},
{input: '> Mention in quote: @**Cordelia Lear**\n\nMention outside quote: @**Cordelia Lear**', {input: '> Mention in quote: @**Cordelia Lear**\n\nMention outside quote: @**Cordelia Lear**',
expected: '<blockquote>\n<p>Mention in quote: <span class="user-mention silent" data-user-id="101">@Cordelia Lear</span></p>\n</blockquote>\n<p>Mention outside quote: <span class="user-mention" data-user-id="101">@Cordelia Lear</span></p>'}, expected: '<blockquote>\n<p>Mention in quote: <span class="user-mention silent" data-user-id="101">@Cordelia Lear</span></p>\n</blockquote>\n<p>Mention outside quote: <span class="user-mention" data-user-id="101">@Cordelia Lear</span></p>'},

View File

@ -509,7 +509,7 @@ inline.zulip = merge({}, inline.breaks, {
'\ud83d[\ude80-\udeff]|\ud83e[\udd00-\uddff]|' + '\ud83d[\ude80-\udeff]|\ud83e[\udd00-\uddff]|' +
'[\u2000-\u206F]|[\u2300-\u27BF]|[\u2B00-\u2BFF]|' + '[\u2000-\u206F]|[\u2300-\u27BF]|[\u2B00-\u2BFF]|' +
'[\u3000-\u303F]|[\u3200-\u32FF])'), '[\u3000-\u303F]|[\u3200-\u32FF])'),
usermention: /^((_?)@(?:\*\*([^\*]+)\*\*))/, // Match potentially multi-word string between @** ** usermention: /^(@(_?)(?:\*\*([^\*]+)\*\*))/, // Match potentially multi-word string between @** **
groupmention: /^@\*([^\*]+)\*/, // Match multi-word string between @* * groupmention: /^@\*([^\*]+)\*/, // Match multi-word string between @* *
stream: /^#\*\*([^\*]+)\*\*/, stream: /^#\*\*([^\*]+)\*\*/,
avatar: /^!avatar\(([^)]+)\)/, avatar: /^!avatar\(([^)]+)\)/,

View File

@ -254,7 +254,7 @@ def send_signup_message(sender: UserProfile, admin_realm_signup_notifications_st
"stream", "stream",
signup_notifications_stream.name, signup_notifications_stream.name,
"signups", "signups",
"_@**%s|%s** just signed up for Zulip. (total: %i)" % ( "@_**%s|%s** just signed up for Zulip. (total: %i)" % (
user_profile.full_name, user_profile.id, user_count user_profile.full_name, user_profile.id, user_count
) )
) )
@ -3491,7 +3491,7 @@ def do_rename_stream(stream: Stream,
sender, sender,
stream, stream,
"welcome", "welcome",
"_@**%s|%d** renamed stream **%s** to **%s**" % (user_profile.full_name, "@_**%s|%d** renamed stream **%s** to **%s**" % (user_profile.full_name,
user_profile.id, user_profile.id,
old_name, new_name) old_name, new_name)
) )

View File

@ -1358,7 +1358,7 @@ class BlockQuoteProcessor(markdown.blockprocessors.BlockQuoteProcessor):
def clean(self, line: str) -> str: def clean(self, line: str) -> str:
# Silence all the mentions inside blockquotes # Silence all the mentions inside blockquotes
line = re.sub(self.mention_re, lambda m: "_@{}".format(m.group('match')), line) line = re.sub(self.mention_re, lambda m: "@_{}".format(m.group('match')), line)
# And then run the upstream processor's code for removing the '>' # And then run the upstream processor's code for removing the '>'
return super().clean(line) return super().clean(line)

View File

@ -5,7 +5,7 @@ import re
# Match multi-word string between @** ** or match any one-word # Match multi-word string between @** ** or match any one-word
# sequences after @ # sequences after @
find_mentions = r'(?<![^\s\'\"\(,:<])(?P<silent>_?)@(?P<match>\*\*[^\*]+\*\*|all|everyone|stream)' find_mentions = r'(?<![^\s\'\"\(,:<])@(?P<silent>_?)(?P<match>\*\*[^\*]+\*\*|all|everyone|stream)'
user_group_mentions = r'(?<![^\s\'\"\(,:<])@(\*[^\*]+\*)' user_group_mentions = r'(?<![^\s\'\"\(,:<])@(\*[^\*]+\*)'
wildcards = ['all', 'everyone', 'stream'] wildcards = ['all', 'everyone', 'stream']

View File

@ -984,7 +984,7 @@ class BugdownTest(ZulipTestCase):
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
user_id = user_profile.id user_id = user_profile.id
content = "_@**King Hamlet**" content = "@_**King Hamlet**"
self.assertEqual(render_markdown(msg, content), self.assertEqual(render_markdown(msg, content),
'<p><span class="user-mention silent" ' '<p><span class="user-mention silent" '
'data-user-id="%s">' 'data-user-id="%s">'
@ -1052,10 +1052,10 @@ class BugdownTest(ZulipTestCase):
content = "> @**King Hamlet**" content = "> @**King Hamlet**"
self.assertEqual(render_markdown(msg, content), expected) self.assertEqual(render_markdown(msg, content), expected)
self.assertEqual(msg.mentions_user_ids, set()) self.assertEqual(msg.mentions_user_ids, set())
content = "```quote\n_@**King Hamlet**\n```" content = "```quote\n@_**King Hamlet**\n```"
self.assertEqual(render_markdown(msg, content), expected) self.assertEqual(render_markdown(msg, content), expected)
self.assertEqual(msg.mentions_user_ids, set()) self.assertEqual(msg.mentions_user_ids, set())
content = "> _@**King Hamlet**" content = "> @_**King Hamlet**"
self.assertEqual(render_markdown(msg, content), expected) self.assertEqual(render_markdown(msg, content), expected)
self.assertEqual(msg.mentions_user_ids, set()) self.assertEqual(msg.mentions_user_ids, set())

View File

@ -193,4 +193,4 @@ class TestNotifyNewUser(ZulipTestCase):
self.assertEqual(message.recipient.type, Recipient.STREAM) self.assertEqual(message.recipient.type, Recipient.STREAM)
actual_stream = Stream.objects.get(id=message.recipient.type_id) actual_stream = Stream.objects.get(id=message.recipient.type_id)
self.assertEqual(actual_stream.name, Realm.INITIAL_PRIVATE_STREAM_NAME) 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) self.assertIn('@_**Cordelia Lear|%d** just signed up for Zulip.' % (new_user.id), message.content)

View File

@ -617,7 +617,7 @@ class StreamAdminTest(ZulipTestCase):
# Inspect the notification message sent # Inspect the notification message sent
message = self.get_last_message() message = self.get_last_message()
actual_stream = Stream.objects.get(id=message.recipient.type_id) actual_stream = Stream.objects.get(id=message.recipient.type_id)
message_content = '_@**King Hamlet|{}** renamed stream **stream_name1** to **stream_name2**'.format(user_profile.id) 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(message.sender.realm, user_profile.realm)
self.assertEqual(actual_stream.name, 'stream_name2') self.assertEqual(actual_stream.name, 'stream_name2')
self.assertEqual(message.recipient.type, Recipient.STREAM) self.assertEqual(message.recipient.type, Recipient.STREAM)
@ -1962,7 +1962,7 @@ class SubscriptionAPITest(ZulipTestCase):
msg = self.get_second_to_last_message() msg = self.get_second_to_last_message()
self.assertEqual(msg.recipient.type, Recipient.STREAM) self.assertEqual(msg.recipient.type, Recipient.STREAM)
self.assertEqual(msg.sender_id, self.notification_bot().id) self.assertEqual(msg.sender_id, self.notification_bot().id)
expected_msg = "_@**%s|%d** just created a new stream #**%s**." % (invitee_full_name, invitee_user.id, 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) self.assertEqual(msg.content, expected_msg)
def test_successful_cross_realm_notification(self) -> None: def test_successful_cross_realm_notification(self) -> None:
@ -2030,7 +2030,7 @@ class SubscriptionAPITest(ZulipTestCase):
msg = self.get_second_to_last_message() msg = self.get_second_to_last_message()
self.assertEqual(msg.sender_id, self.notification_bot().id) self.assertEqual(msg.sender_id, self.notification_bot().id)
expected_msg = "_@**%s|%d** just created a new stream #**%s**." % (invitee_full_name, invitee_user.id, 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) self.assertEqual(msg.content, expected_msg)
def test_non_ascii_stream_subscription(self) -> None: def test_non_ascii_stream_subscription(self) -> None:

View File

@ -389,7 +389,7 @@ def add_subscriptions_backend(
stream_msg = "the following streams: %s" % (stream_strs,) stream_msg = "the following streams: %s" % (stream_strs,)
else: else:
stream_msg = "a new stream #**%s**." % created_streams[0].name stream_msg = "a new stream #**%s**." % created_streams[0].name
msg = ("_@**%s|%d** just created %s" % (user_profile.full_name, user_profile.id, stream_msg)) msg = ("@_**%s|%d** just created %s" % (user_profile.full_name, user_profile.id, stream_msg))
sender = get_system_bot(settings.NOTIFICATION_BOT) sender = get_system_bot(settings.NOTIFICATION_BOT)
topic = 'Streams' topic = 'Streams'