message_edit: Sort message_ids when sending update_message event.

https://chat.zulip.org/#narrow/channel/412-api-documentation/topic/Make.20message_ids.20from.20message.20update.20event.20sorted
This commit is contained in:
Shubham Padia
2025-06-17 10:43:13 +00:00
committed by Tim Abbott
parent 4f67c1dbf1
commit 37bfb7c963
5 changed files with 21 additions and 9 deletions

View File

@@ -0,0 +1,4 @@
* [`PATCH /messages/{message_id}`](/api/update-message),
[`POST /register`](/api/register-queue), [`GET /events`](/api/get-events):
In `update_message` event, all the `message_ids` will now be sorted in
increasing order.

View File

@@ -529,9 +529,6 @@ export function update_messages(events: UpdateMessageEvent[]): void {
local_cache_missing_messages = true;
}
}
// The event.message_ids received from the server are not in sorted order.
// Sorts in ascending order.
event_messages.sort((a, b) => a.id - b.id);
if (
going_forward_change &&

View File

@@ -680,7 +680,7 @@ def do_update_message(
# This does message.save(update_fields=[...])
save_message_for_edit_use_case(message=target_message)
event["message_ids"] = update_message_cache([target_message])
event["message_ids"] = sorted(update_message_cache([target_message]))
users_to_be_notified = list(map(user_info, ums))
send_event_on_commit(user_profile.realm, event, users_to_be_notified)
@@ -890,7 +890,7 @@ def do_update_message(
changed_messages = save_changes_for_propagation_mode()
realm_id = target_message.realm_id
event["message_ids"] = update_message_cache(changed_messages, realm_id)
event["message_ids"] = sorted(update_message_cache(changed_messages, realm_id))
# The following blocks arranges that users who are subscribed to a
# stream and can see history from before they subscribed get

View File

@@ -2473,8 +2473,8 @@ paths:
items:
type: integer
description: |
The list of IDs of messages to which any channel or topic changes
encoded in this event should be applied.
A sorted list of IDs of messages to which any channel or topic
changes encoded in this event should be applied.
This list always includes `message_id`, even when there are no
channel or topic changes to apply.
@@ -2492,6 +2492,9 @@ paths:
Content changes should be applied only to the single message
indicated by `message_id`.
**Changes**: Before Zulip 11.0 (feature level ZF-908160), this list
was not guaranteed to be sorted.
flags:
type: array
description: |
@@ -2717,7 +2720,7 @@ paths:
"orig_subject": "test",
"subject": "new_topic",
"topic_links": [],
"message_ids": [58, 57],
"message_ids": [57, 58],
"flags": [],
"rendering_only": false,
"id": 0,

View File

@@ -1040,9 +1040,15 @@ class NormalActionsTest(BaseAction):
# Verify move topic to different stream.
self.subscribe(self.user_profile, "Verona")
self.subscribe(self.user_profile, "Denmark")
self.send_stream_message(iago, "Verona")
# Message passed to the message edit request is usually last in
# event["message_ids"]. Since we want to test sorting of these
# message_ids later on, we need send the message_id to be used
# in the message_edit_request first; Otherwise
# event["message_ids"] would be sorted even without any sorting
# function.
message_id = self.send_stream_message(self.user_profile, "Verona")
message = Message.objects.get(id=message_id)
self.send_stream_message(iago, "Verona")
stream = get_stream("Denmark", self.user_profile.realm)
propagate_mode = "change_all"
prior_mention_user_ids = set()
@@ -1081,6 +1087,8 @@ class NormalActionsTest(BaseAction):
has_new_stream_id=True,
is_embedded_update_only=False,
)
# Make sure the message_ids returned are sorted.
self.assertEqual(events[0]["message_ids"], sorted(events[0]["message_ids"]))
# Move both stream and topic, with update_message_flags
# excluded from event types.