mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
[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:
@@ -273,6 +273,7 @@ def do_send_messages(messages):
|
|||||||
raise ValueError('Bad recipient type')
|
raise ValueError('Bad recipient type')
|
||||||
|
|
||||||
# Save the message receipts in the database
|
# Save the message receipts in the database
|
||||||
|
user_message_flags = defaultdict(dict)
|
||||||
with transaction.commit_on_success():
|
with transaction.commit_on_success():
|
||||||
Message.objects.bulk_create([message['message'] for message in messages])
|
Message.objects.bulk_create([message['message'] for message in messages])
|
||||||
ums = []
|
ums = []
|
||||||
@@ -288,6 +289,7 @@ def do_send_messages(messages):
|
|||||||
um.flags |= UserMessage.flags.read
|
um.flags |= UserMessage.flags.read
|
||||||
if wildcard or um.user_profile in mentioned:
|
if wildcard or um.user_profile in mentioned:
|
||||||
um.flags |= UserMessage.flags.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)
|
ums.extend(ums_to_create)
|
||||||
UserMessage.objects.bulk_create(ums)
|
UserMessage.objects.bulk_create(ums)
|
||||||
|
|
||||||
@@ -302,10 +304,11 @@ def do_send_messages(messages):
|
|||||||
# doesn't have to.
|
# doesn't have to.
|
||||||
message['message'].to_dict(apply_markdown=True, rendered_content=message['rendered_content'])
|
message['message'].to_dict(apply_markdown=True, rendered_content=message['rendered_content'])
|
||||||
message['message'].to_dict(apply_markdown=False)
|
message['message'].to_dict(apply_markdown=False)
|
||||||
|
user_flags = user_message_flags.get(message['message'].id, {})
|
||||||
data = dict(
|
data = dict(
|
||||||
type = 'new_message',
|
type = 'new_message',
|
||||||
message = message['message'].id,
|
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:
|
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
|
||||||
|
|||||||
@@ -792,7 +792,9 @@ function get_updates(options) {
|
|||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'message':
|
case 'message':
|
||||||
messages.push(event.message);
|
var msg = event.message;
|
||||||
|
msg.flags = event.flags;
|
||||||
|
messages.push(msg);
|
||||||
break;
|
break;
|
||||||
case 'pointer':
|
case 'pointer':
|
||||||
new_pointer = event.pointer;
|
new_pointer = event.pointer;
|
||||||
|
|||||||
@@ -270,10 +270,10 @@ def process_new_message(data):
|
|||||||
elif type(first) == int:
|
elif type(first) == int:
|
||||||
user_ids = data['users']
|
user_ids = data['users']
|
||||||
|
|
||||||
|
|
||||||
for user_profile_id in user_ids:
|
for user_profile_id in user_ids:
|
||||||
user_receive_message(user_profile_id, message)
|
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):
|
for client in get_client_descriptors_for_user(user_profile_id):
|
||||||
# The below prevents (Zephyr) mirroring loops.
|
# The below prevents (Zephyr) mirroring loops.
|
||||||
if client.accepts_event_type('message') and not \
|
if client.accepts_event_type('message') and not \
|
||||||
@@ -283,7 +283,7 @@ def process_new_message(data):
|
|||||||
message_dict = message_dict_markdown
|
message_dict = message_dict_markdown
|
||||||
else:
|
else:
|
||||||
message_dict = message_dict_no_markdown
|
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)
|
client.add_event(event)
|
||||||
|
|
||||||
# If the recipient was offline and the message was a single or group PM,
|
# If the recipient was offline and the message was a single or group PM,
|
||||||
|
|||||||
Reference in New Issue
Block a user