mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
Fix @-mentions.
Trying to check whether a Django model object is inside a set of other
Django models is not correct in general, e.g.:
UserProfile.objects.only("id").get(id=17) in set([UserProfile.objects.get(id=17)])
returns False.
This bug appears twice in the function, once when computing which
users were mentioned and again when pushing the flags through to
Tornado.
(imported from commit b09ed550258f9df2611e1b0a60f87c48a51830f8)
This commit is contained in:
@@ -219,7 +219,7 @@ def mentioned_in_message(message):
|
|||||||
for attempt in attempts:
|
for attempt in attempts:
|
||||||
ups = UserProfile.objects.filter(attempt, realm=message.sender.realm)
|
ups = UserProfile.objects.filter(attempt, realm=message.sender.realm)
|
||||||
for user in ups:
|
for user in ups:
|
||||||
users.add(user)
|
users.add(user.id)
|
||||||
found = len(ups) > 0
|
found = len(ups) > 0
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -279,17 +279,17 @@ def do_send_messages(messages):
|
|||||||
ums_to_create = [UserMessage(user_profile=user_profile, message=message['message'])
|
ums_to_create = [UserMessage(user_profile=user_profile, message=message['message'])
|
||||||
for user_profile in message['recipients']
|
for user_profile in message['recipients']
|
||||||
if user_profile.is_active]
|
if user_profile.is_active]
|
||||||
|
wildcard, mentioned_ids = mentioned_in_message(message['message'])
|
||||||
for um in ums_to_create:
|
for um in ums_to_create:
|
||||||
wildcard, mentioned = mentioned_in_message(message['message'])
|
|
||||||
sent_by_human = message['message'].sending_client.name.lower() in \
|
sent_by_human = message['message'].sending_client.name.lower() in \
|
||||||
['website', 'iphone', 'android']
|
['website', 'iphone', 'android']
|
||||||
if um.user_profile == message['message'].sender and sent_by_human:
|
if um.user_profile == message['message'].sender and sent_by_human:
|
||||||
um.flags |= UserMessage.flags.read
|
um.flags |= UserMessage.flags.read
|
||||||
if wildcard:
|
if wildcard:
|
||||||
um.flags |= UserMessage.flags.wildcard_mentioned
|
um.flags |= UserMessage.flags.wildcard_mentioned
|
||||||
if um.user_profile in mentioned:
|
if um.user_profile_id in mentioned_ids:
|
||||||
um.flags |= UserMessage.flags.mentioned
|
um.flags |= UserMessage.flags.mentioned
|
||||||
user_message_flags[message['message'].id][um.user_profile] = um.flags_dict().get('flags')
|
user_message_flags[message['message'].id][um.user_profile_id] = um.flags_list()
|
||||||
ums.extend(ums_to_create)
|
ums.extend(ums_to_create)
|
||||||
UserMessage.objects.bulk_create(ums)
|
UserMessage.objects.bulk_create(ums)
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ def do_send_messages(messages):
|
|||||||
data = dict(
|
data = dict(
|
||||||
type = 'new_message',
|
type = 'new_message',
|
||||||
message = message['message'].id,
|
message = message['message'].id,
|
||||||
users = [{'id': user.id, 'flags': user_flags.get(user, [])} for user in message['recipients']])
|
users = [{'id': user.id, 'flags': user_flags.get(user.id, [])} for user in message['recipients']])
|
||||||
if message['message'].recipient.type == Recipient.STREAM:
|
if message['message'].recipient.type == Recipient.STREAM:
|
||||||
# Note: This is where authorization for single-stream
|
# Note: This is where authorization for single-stream
|
||||||
# get_updates happens! We only attach stream data to the
|
# get_updates happens! We only attach stream data to the
|
||||||
|
|||||||
Reference in New Issue
Block a user