[manual] Send UserMessage flags in get_events updates

This commit must be deployed in a separate step from the previous [manual]
commit

(imported from commit c6f00e217062790fce8380f61f82ea8824fb3722)
This commit is contained in:
Leo Franchi
2013-05-17 13:50:12 -04:00
committed by Tim Abbott
parent 3c81664641
commit b548538a98
3 changed files with 9 additions and 4 deletions

View File

@@ -273,6 +273,7 @@ def do_send_messages(messages):
raise ValueError('Bad recipient type')
# Save the message receipts in the database
user_message_flags = defaultdict(dict)
with transaction.commit_on_success():
Message.objects.bulk_create([message['message'] for message in messages])
ums = []
@@ -288,6 +289,7 @@ def do_send_messages(messages):
um.flags |= UserMessage.flags.read
if wildcard or um.user_profile in mentioned:
um.flags |= UserMessage.flags.mentioned
user_message_flags[message['message'].id][um.user_profile] = um.flags_dict().get('flags')
ums.extend(ums_to_create)
UserMessage.objects.bulk_create(ums)
@@ -302,10 +304,11 @@ def do_send_messages(messages):
# doesn't have to.
message['message'].to_dict(apply_markdown=True, rendered_content=message['rendered_content'])
message['message'].to_dict(apply_markdown=False)
user_flags = user_message_flags.get(message['message'].id, {})
data = dict(
type = 'new_message',
message = message['message'].id,
users = [user.id for user in message['recipients']])
users = [{'id': user.id, 'flags': user_flags.get(user, [])} for user in message['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

View File

@@ -792,7 +792,9 @@ function get_updates(options) {
switch (event.type) {
case 'message':
messages.push(event.message);
var msg = event.message;
msg.flags = event.flags;
messages.push(msg);
break;
case 'pointer':
new_pointer = event.pointer;

View File

@@ -270,10 +270,10 @@ def process_new_message(data):
elif type(first) == int:
user_ids = data['users']
for user_profile_id in user_ids:
user_receive_message(user_profile_id, message)
flags = user_flags.get(user_profile_id, [])
for client in get_client_descriptors_for_user(user_profile_id):
# The below prevents (Zephyr) mirroring loops.
if client.accepts_event_type('message') and not \
@@ -283,7 +283,7 @@ def process_new_message(data):
message_dict = message_dict_markdown
else:
message_dict = message_dict_no_markdown
event = dict(type='message', message=message_dict)
event = dict(type='message', message=message_dict, flags=flags)
client.add_event(event)
# If the recipient was offline and the message was a single or group PM,