2013-06-28 16:02:58 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
from django.db.models import F, Q
|
2013-07-29 23:03:31 +02:00
|
|
|
import zerver.models
|
2013-06-28 16:02:58 +02:00
|
|
|
|
|
|
|
# Match multi-word string between @** ** or match any one-word
|
|
|
|
# sequences after @
|
2013-07-12 20:26:09 +02:00
|
|
|
find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
|
2013-06-28 16:02:58 +02:00
|
|
|
|
|
|
|
wildcards = ['all', 'everyone']
|
|
|
|
|
|
|
|
def find_user_for_mention(mention, realm):
|
|
|
|
if mention in wildcards:
|
|
|
|
return (True, None)
|
|
|
|
|
|
|
|
try:
|
2013-07-29 23:03:31 +02:00
|
|
|
user = zerver.models.UserProfile.objects.filter(
|
2013-06-28 16:02:58 +02:00
|
|
|
Q(full_name__iexact=mention) | Q(short_name__iexact=mention),
|
2013-07-17 20:07:40 +02:00
|
|
|
is_active=True,
|
2013-07-17 20:14:34 +02:00
|
|
|
realm=realm).order_by("id")[0]
|
2013-06-28 16:02:58 +02:00
|
|
|
except IndexError:
|
|
|
|
user = None
|
|
|
|
|
|
|
|
return (False, user)
|