Add presences info to the event data for process_new_message().

The do_send_messages() populates the user_presences data structure
for process_new_message(), so that Tornado code never needs to hit
the database or memcached to get the user presence info.

(imported from commit 194aeaead8fa712297a2ee8aff5aa773b92f1207)
This commit is contained in:
Steve Howell
2013-09-15 13:10:16 -04:00
parent a4744b10ed
commit 99dd2ed8df
3 changed files with 17 additions and 27 deletions

View File

@@ -298,10 +298,18 @@ def do_send_messages(messages):
message['message'].to_dict(apply_markdown=True)
message['message'].to_dict(apply_markdown=False)
user_flags = user_message_flags.get(message['message'].id, {})
sender = message['message'].sender
recipient_emails = [user.email for user in message['recipients']]
user_presences = get_status_dict(sender)
presences = {}
for email in recipient_emails:
if email in user_presences:
presences[email] = user_presences[email]
data = dict(
type = 'new_message',
message = message['message'].id,
sender_realm = message['message'].sender.realm.id,
presences = user_presences,
users = [{'id': user.id, 'flags': user_flags.get(user.id, [])}
for user in message['recipients']])
if message['message'].recipient.type == Recipient.STREAM: