mirror of https://github.com/zulip/zulip.git
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)
This commit is contained in:
parent
4bf3ace444
commit
1470cb8bf4
|
@ -309,6 +309,9 @@ def do_send_messages(messages):
|
||||||
else:
|
else:
|
||||||
raise ValueError('Bad recipient type')
|
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)
|
message['message'].maybe_render_content(None)
|
||||||
|
|
||||||
# Save the message receipts in the database
|
# Save the message receipts in the database
|
||||||
|
@ -318,8 +321,7 @@ def do_send_messages(messages):
|
||||||
ums = []
|
ums = []
|
||||||
for message in messages:
|
for message in 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['active_recipients']]
|
||||||
if user_profile.is_active]
|
|
||||||
|
|
||||||
# These properties on the Message are set via
|
# These properties on the Message are set via
|
||||||
# Message.render_markdown by code in the bugdown inline patterns
|
# 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)
|
message['message'].to_dict(apply_markdown=False)
|
||||||
user_flags = user_message_flags.get(message['message'].id, {})
|
user_flags = user_message_flags.get(message['message'].id, {})
|
||||||
sender = message['message'].sender
|
sender = message['message'].sender
|
||||||
recipient_emails = [user.email for user in message['recipients']]
|
|
||||||
user_presences = get_status_dict(sender)
|
user_presences = get_status_dict(sender)
|
||||||
presences = {}
|
presences = {}
|
||||||
for email in recipient_emails:
|
for user_profile in message['active_recipients']:
|
||||||
if email in user_presences:
|
if user_profile.email in user_presences:
|
||||||
presences[email] = user_presences[email]
|
presences[user_profile.email] = user_presences[user_profile.email]
|
||||||
|
|
||||||
data = dict(
|
data = dict(
|
||||||
type = 'new_message',
|
type = 'new_message',
|
||||||
message = message['message'].id,
|
message = message['message'].id,
|
||||||
presences = presences,
|
presences = presences,
|
||||||
users = [{'id': user.id, 'flags': user_flags.get(user.id, [])}
|
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:
|
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
|
||||||
|
|
Loading…
Reference in New Issue