mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 15:33:30 +00:00
Fixes issues with e.g. foo@hamlet.com (where hamlet is a user) The \b was ineffective because @ made it always on a word boundary. Instead, use the negative lookbehind trick from the URL regex. (imported from commit fdca9bd686e4f8747e67b412cba1fa7c5c9391aa)
26 lines
654 B
Python
26 lines
654 B
Python
import re
|
|
|
|
from django.db.models import F, Q
|
|
import zephyr.models
|
|
|
|
# Match multi-word string between @** ** or match any one-word
|
|
# sequences after @
|
|
find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
|
|
find_mentions_re = re.compile(find_mentions)
|
|
|
|
wildcards = ['all', 'everyone']
|
|
|
|
def find_user_for_mention(mention, realm):
|
|
if mention in wildcards:
|
|
return (True, None)
|
|
|
|
try:
|
|
user = zephyr.models.UserProfile.objects.filter(
|
|
Q(full_name__iexact=mention) | Q(short_name__iexact=mention),
|
|
realm=realm
|
|
)[0]
|
|
except IndexError:
|
|
user = None
|
|
|
|
return (False, user)
|