mirror of https://github.com/zulip/zulip.git
25 lines
643 B
Python
25 lines
643 B
Python
import re
|
|
|
|
from django.db.models import F, Q
|
|
import zerver.models
|
|
|
|
# Match multi-word string between @** ** or match any one-word
|
|
# sequences after @
|
|
find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
|
|
|
|
wildcards = ['all', 'everyone']
|
|
|
|
def find_user_for_mention(mention, realm):
|
|
if mention in wildcards:
|
|
return (True, None)
|
|
|
|
try:
|
|
user = zerver.models.UserProfile.objects.filter(
|
|
Q(full_name__iexact=mention) | Q(short_name__iexact=mention),
|
|
is_active=True,
|
|
realm=realm).order_by("id")[0]
|
|
except IndexError:
|
|
user = None
|
|
|
|
return (False, user)
|