Preparatory changes to Tornado server for receiving a single stream's messages

Doesn't yet add the API for actually doing so.

(imported from commit a2062d71544441256a41f817388bb0c7ea6891ff)
This commit is contained in:
Reid Barton
2013-01-15 13:52:22 -05:00
parent 7b7f6390f9
commit c9e2fed3f9
2 changed files with 86 additions and 20 deletions

View File

@@ -168,10 +168,21 @@ def do_send_message(message, no_log=False):
# doesn't have to.
message.to_dict(apply_markdown=True)
message.to_dict(apply_markdown=False)
requests.post(settings.TORNADO_SERVER + '/notify_new_message', data=dict(
data = dict(
secret = settings.SHARED_SECRET,
message = message.id,
users = simplejson.dumps([str(user.id) for user in recipients])))
users = simplejson.dumps([str(user.id) for user in recipients]))
if message.recipient.type == Recipient.STREAM:
# Note: This is where authorization for single-stream
# get_updates happens! We only attach stream data to the
# notify_new_message request if it's a public stream,
# ensuring that in the tornado server, non-public stream
# messages are only associated to their subscribed users.
stream = Stream.objects.get(id=message.recipient.type_id)
if stream.is_public():
data['realm_id'] = stream.realm.id
data['stream_name'] = stream.name
requests.post(settings.TORNADO_SERVER + '/notify_new_message', data=data)
def create_stream_if_needed(realm, stream_name):
(stream, created) = Stream.objects.get_or_create(