bugdown: Fully remove mentions matching @name.

Given typeahed and the fact that this only worked if the person had a
full name that didn't contain whitespace, this side effect of the
original @shortname mentionfeature that we removed was experienced by
users as a bug.

Fixes #6142.
This commit is contained in:
Tim Abbott 2017-08-16 11:18:09 -07:00
parent b165784264
commit d2288154f6
3 changed files with 23 additions and 16 deletions

View File

@ -1104,24 +1104,20 @@ class RealmFilterPattern(markdown.inlinepatterns.Pattern):
m.group("name"))
class UserMentionPattern(markdown.inlinepatterns.Pattern):
def find_user_for_mention(self, name):
# type: (Text) -> Tuple[bool, Optional[Dict[str, Any]]]
if db_data is None:
return (False, None)
if mention.user_mention_matches_wildcard(name):
return (True, None)
user = db_data['full_names'].get(name.lower(), None)
return (False, user)
def handleMatch(self, m):
# type: (Match[Text]) -> Optional[Element]
name = m.group(2) or m.group(3)
match = m.group(2)
if current_message:
wildcard, user = self.find_user_for_mention(name)
if current_message and db_data is not None:
if match.startswith("**") and match.endswith("**"):
name = match[2:-2]
else:
if not mention.user_mention_matches_wildcard(match):
return
name = match
wildcard = mention.user_mention_matches_wildcard(name)
user = db_data['full_names'].get(name.lower(), None)
if wildcard:
current_message.mentions_wildcard = True

View File

@ -3,7 +3,7 @@ from __future__ import absolute_import
from typing import Text
# Match multi-word string between @** ** or match any one-word
# sequences after @
find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
find_mentions = r'(?<![^\s\'\"\(,:<])@(\*\*[^\*]+\*\*|\w+)'
wildcards = ['all', 'everyone']

View File

@ -714,6 +714,17 @@ class BugdownTest(ZulipTestCase):
'<p><span class="user-mention" data-user-email="*" data-user-id="*">@everyone</span> test</p>')
self.assertTrue(msg.mentions_wildcard)
def test_mention_everyone(self):
# type: () -> None
user_profile = self.example_user('othello')
msg = Message(sender=user_profile, sending_client=get_client("test"))
content = "@aaron test"
self.assertEqual(render_markdown(msg, content),
'<p>@aaron test</p>')
self.assertFalse(msg.mentions_wildcard)
self.assertEqual(msg.mentions_user_ids, set([]))
def test_mention_single(self):
# type: () -> None
sender_user_profile = self.example_user('othello')