message_delete: Sort message_ids when sending delete_message event.

Fixes #34324.
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 11:04:22 +00:00
committed by Tim Abbott
parent 37bfb7c963
commit 00fe2236da
4 changed files with 14 additions and 3 deletions

View File

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

View File

@@ -64,7 +64,7 @@ def _process_grouped_messages_deletion(
event: DeleteMessagesEvent = {
"type": "delete_message",
"message_ids": message_ids,
"message_ids": sorted(message_ids),
}
if stream is None:
assert topic is None

View File

@@ -2136,7 +2136,10 @@ paths:
Only present for clients that support the `bulk_message_deletion`
[client capability][client-capabilities].
A list containing the IDs of the newly deleted messages.
A sorted list containing the IDs of the newly deleted messages.
**Changes**: Before Zulip 11.0 (feature level ZF-215011), this list was
not guaranteed to be sorted.
[client-capabilities]: /api/register-queue#parameter-client_capabilities
items:

View File

@@ -3938,7 +3938,10 @@ class NormalActionsTest(BaseAction):
hamlet = self.example_user("hamlet")
msg_id = self.send_stream_message(hamlet, "Verona")
msg_id_2 = self.send_stream_message(hamlet, "Verona")
messages = [Message.objects.get(id=msg_id), Message.objects.get(id=msg_id_2)]
# Pass messages in reverse sorted order, so we can test that
# the backend is sorting the messages_ids sent in the delete
# event.
messages = [Message.objects.get(id=msg_id_2), Message.objects.get(id=msg_id)]
with self.verify_action(state_change_expected=True) as events:
do_delete_messages(self.user_profile.realm, messages, acting_user=None)
check_delete_message(
@@ -3948,6 +3951,7 @@ class NormalActionsTest(BaseAction):
num_message_ids=2,
is_legacy=False,
)
self.assertEqual(events[0]["message_ids"], sorted(events[0]["message_ids"]))
def test_do_delete_message_stream_legacy(self) -> None:
"""