Simplify do_send_messages() from prior commit.

This change removes an "if True:" that was
introduced to make the prior commit a bit more readable.
It also combines two loops, since the second loop is no
longer conditional.

(imported from commit df58f1e5de72d5669f6468fbff54fb62cd22cedb)
This commit is contained in:
Steve Howell
2013-07-01 18:14:58 -04:00
parent a4db7de330
commit d94f91fd43

View File

@@ -295,32 +295,28 @@ def do_send_messages(messages):
for message in messages: for message in messages:
cache_save_message(message['message']) cache_save_message(message['message'])
# Render Markdown etc. here and store (automatically) in
# We can only publish messages to longpolling clients if the Tornado server is running. # memcached, so that the single-threaded Tornado server
if True: # doesn't have to.
for message in messages: message['message'].to_dict(apply_markdown=True, rendered_content=message['rendered_content'])
# Render Markdown etc. here and store (automatically) in message['message'].to_dict(apply_markdown=False)
# memcached, so that the single-threaded Tornado server user_flags = user_message_flags.get(message['message'].id, {})
# doesn't have to. data = dict(
message['message'].to_dict(apply_markdown=True, rendered_content=message['rendered_content']) type = 'new_message',
message['message'].to_dict(apply_markdown=False) message = message['message'].id,
user_flags = user_message_flags.get(message['message'].id, {}) users = [{'id': user.id, 'flags': user_flags.get(user.id, [])} for user in message['recipients']])
data = dict( if message['message'].recipient.type == Recipient.STREAM:
type = 'new_message', # Note: This is where authorization for single-stream
message = message['message'].id, # get_updates happens! We only attach stream data to the
users = [{'id': user.id, 'flags': user_flags.get(user.id, [])} for user in message['recipients']]) # notify new_message request if it's a public stream,
if message['message'].recipient.type == Recipient.STREAM: # ensuring that in the tornado server, non-public stream
# Note: This is where authorization for single-stream # messages are only associated to their subscribed users.
# get_updates happens! We only attach stream data to the if message['stream'] is None:
# notify new_message request if it's a public stream, message['stream'] = Stream.objects.select_related("realm").get(id=message['message'].recipient.type_id)
# ensuring that in the tornado server, non-public stream if message['stream'].is_public():
# messages are only associated to their subscribed users. data['realm_id'] = message['stream'].realm.id
if message['stream'] is None: data['stream_name'] = message['stream'].name
message['stream'] = Stream.objects.select_related("realm").get(id=message['message'].recipient.type_id) tornado_callbacks.send_notification(data)
if message['stream'].is_public():
data['realm_id'] = message['stream'].realm.id
data['stream_name'] = message['stream'].name
tornado_callbacks.send_notification(data)
def create_stream_if_needed(realm, stream_name, invite_only=False): def create_stream_if_needed(realm, stream_name, invite_only=False):
(stream, created) = Stream.objects.get_or_create( (stream, created) = Stream.objects.get_or_create(