Process message events more similarly to how other events are handled.

(imported from commit 5ebcd7a10fe54a8ecafb9550348a1e0418d4cbda)
This commit is contained in:
Tim Abbott
2014-01-27 13:48:32 -05:00
parent 934ac3fc88
commit 3fddc11cc2
3 changed files with 23 additions and 23 deletions

View File

@@ -50,9 +50,7 @@ from zerver.lib.push_notifications import num_push_devices_for_user, \
send_apple_push_notification, send_android_push_notification send_apple_push_notification, send_android_push_notification
from zerver.lib.notifications import clear_followup_emails_queue from zerver.lib.notifications import clear_followup_emails_queue
from zerver.lib.narrow import check_supported_events_narrow_filter from zerver.lib.narrow import check_supported_events_narrow_filter
from zerver.tornado_callbacks import send_event from zerver.tornado_callbacks import send_event
from zerver import tornado_callbacks
import DNS import DNS
import ujson import ujson
@@ -364,16 +362,16 @@ def do_send_messages(messages):
if user_profile.email in user_presences: if user_profile.email in user_presences:
presences[user_profile.id] = user_presences[user_profile.email] presences[user_profile.id] = user_presences[user_profile.email]
data = dict( event = dict(
type = 'new_message', type = 'message',
message = message['message'].id, message = message['message'].id,
message_dict_markdown = message['message'].to_dict(apply_markdown=True), message_dict_markdown = message['message'].to_dict(apply_markdown=True),
message_dict_no_markdown = message['message'].to_dict(apply_markdown=False), message_dict_no_markdown = message['message'].to_dict(apply_markdown=False),
presences = presences, presences = presences)
users = [{'id': user.id, users = [{'id': user.id,
'flags': user_flags.get(user.id, []), 'flags': user_flags.get(user.id, []),
'always_push_notify': always_push_notify(user)} 'always_push_notify': always_push_notify(user)}
for user in message['active_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
@@ -383,15 +381,15 @@ def do_send_messages(messages):
if message['stream'] is None: if message['stream'] is None:
message['stream'] = Stream.objects.select_related("realm").get(id=message['message'].recipient.type_id) message['stream'] = Stream.objects.select_related("realm").get(id=message['message'].recipient.type_id)
if message['stream'].is_public(): if message['stream'].is_public():
data['realm_id'] = message['stream'].realm.id event['realm_id'] = message['stream'].realm.id
data['stream_name'] = message['stream'].name event['stream_name'] = message['stream'].name
if message['stream'].invite_only: if message['stream'].invite_only:
data['invite_only'] = True event['invite_only'] = True
if message['local_id'] is not None: if message['local_id'] is not None:
data['local_id'] = message['local_id'] event['local_id'] = message['local_id']
if message['sender_queue_id'] is not None: if message['sender_queue_id'] is not None:
data['sender_queue_id'] = message['sender_queue_id'] event['sender_queue_id'] = message['sender_queue_id']
tornado_callbacks.send_notification(data) send_event(event, users)
if (settings.ENABLE_FEEDBACK and if (settings.ENABLE_FEEDBACK and
message['message'].recipient.type == Recipient.PERSONAL and message['message'].recipient.type == Recipient.PERSONAL and
settings.FEEDBACK_BOT in [up.email for up in message['recipients']]): settings.FEEDBACK_BOT in [up.email for up in message['recipients']]):

View File

@@ -2293,7 +2293,7 @@ class SubscriptionAPITest(AuthedTestCase):
self.assert_length(queries, 37) self.assert_length(queries, 37)
self.assert_length(events, 4, exact=True) self.assert_length(events, 4, exact=True)
for ev in filter(lambda x: 'message' not in x, events): for ev in filter(lambda x: x['event']['type'] != 'message', events):
self.assertEqual(ev['event']['op'], 'add') self.assertEqual(ev['event']['op'], 'add')
self.assertEqual( self.assertEqual(
set(ev['event']['subscriptions'][0]['subscribers']), set(ev['event']['subscriptions'][0]['subscribers']),

View File

@@ -93,7 +93,7 @@ def receiver_is_idle(user_profile_id, realm_presences):
return off_zulip or idle_too_long return off_zulip or idle_too_long
def process_new_message(event_template): def process_message_event(event_template, users):
realm_presences = event_template['presences'] realm_presences = event_template['presences']
sender_queue_id = event_template.get('sender_queue_id', None) sender_queue_id = event_template.get('sender_queue_id', None)
if "message_dict_markdown" in event_template: if "message_dict_markdown" in event_template:
@@ -122,7 +122,7 @@ def process_new_message(event_template):
if sender_queue_id is not None and client.event_queue.id == sender_queue_id: if sender_queue_id is not None and client.event_queue.id == sender_queue_id:
send_to_clients[client.event_queue.id]['is_sender'] = True send_to_clients[client.event_queue.id]['is_sender'] = True
for user_data in event_template['users']: for user_data in users:
user_profile_id = user_data['id'] user_profile_id = user_data['id']
flags = user_data.get('flags', []) flags = user_data.get('flags', [])
@@ -208,13 +208,13 @@ def process_userdata_event(event_template, users):
if client.accepts_event(user_event): if client.accepts_event(user_event):
client.add_event(user_event) client.add_event(user_event)
def process_notification(data): def process_notification(notice):
event = data['event'] event = notice['event']
users = data['users'] users = notice['users']
if event['type'] in ["update_message"]: if event['type'] in ["update_message"]:
process_userdata_event(event, users) process_userdata_event(event, users)
elif event['type'] == "message": elif event['type'] == "message":
process_new_message(data) process_message_event(event, users)
else: else:
process_event(event, users) process_event(event, users)
@@ -235,4 +235,6 @@ def send_notification(data):
return queue_json_publish("notify_tornado", data, send_notification_http) return queue_json_publish("notify_tornado", data, send_notification_http)
def send_event(event, users): def send_event(event, users):
return send_notification(dict(event=event, users=users)) return queue_json_publish("notify_tornado",
dict(event=event, users=users),
send_notification_http)