From 1470cb8bf4f30db8ee7d54ad4c92aea9c2245f13 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 7 Jan 2014 14:52:11 -0500 Subject: [PATCH] do_send_messages: Only pass active recipient users to Tornado. Previously, we were processing in Tornado mirroring dummy users (and deactived users) as recipients -- resulting in bugs where the missed message hooks would fire for these nonexistent users. Our Tornado real-time delivery system only needs the list of active users both for delivery and for presence information updates. (imported from commit b81143f106a4d0eefa4b838e7c074b2963259746) --- zerver/lib/actions.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 8b324d2e77..7274b8e7c6 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -309,6 +309,9 @@ def do_send_messages(messages): else: raise ValueError('Bad recipient type') + # Only deliver the message to active user recipients + message['active_recipients'] = filter(lambda user_profile: user_profile.is_active, + message['recipients']) message['message'].maybe_render_content(None) # Save the message receipts in the database @@ -318,8 +321,7 @@ def do_send_messages(messages): ums = [] for message in messages: ums_to_create = [UserMessage(user_profile=user_profile, message=message['message']) - for user_profile in message['recipients'] - if user_profile.is_active] + for user_profile in message['active_recipients']] # These properties on the Message are set via # Message.render_markdown by code in the bugdown inline patterns @@ -350,19 +352,18 @@ def do_send_messages(messages): 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] + for user_profile in message['active_recipients']: + if user_profile.email in user_presences: + presences[user_profile.email] = user_presences[user_profile.email] data = dict( type = 'new_message', message = message['message'].id, presences = presences, users = [{'id': user.id, 'flags': user_flags.get(user.id, [])} - for user in message['recipients']]) + for user in message['active_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