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:
Tim Abbott
2013-06-25 13:29:37 -04:00
parent d537bf568c
commit d6e04ce2d6

View File

@@ -219,7 +219,7 @@ def mentioned_in_message(message):
for attempt in attempts:
ups = UserProfile.objects.filter(attempt, realm=message.sender.realm)
for user in ups:
users.add(user)
users.add(user.id)
found = len(ups) > 0
break
@@ -279,17 +279,17 @@ def do_send_messages(messages):
ums_to_create = [UserMessage(user_profile=user_profile, message=message['message'])
for user_profile in message['recipients']
if user_profile.is_active]
wildcard, mentioned_ids = mentioned_in_message(message['message'])
for um in ums_to_create:
wildcard, mentioned = mentioned_in_message(message['message'])
sent_by_human = message['message'].sending_client.name.lower() in \
['website', 'iphone', 'android']
if um.user_profile == message['message'].sender and sent_by_human:
um.flags |= UserMessage.flags.read
if wildcard:
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
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)
UserMessage.objects.bulk_create(ums)
@@ -308,7 +308,7 @@ def do_send_messages(messages):
data = dict(
type = 'new_message',
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:
# Note: This is where authorization for single-stream
# get_updates happens! We only attach stream data to the