Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_edit: Sort message_ids when sending update_message event.
Shubham Padia37bfb7c963e4
diff --git a/api_docs/unmerged.d/ZF-908160.md b/api_docs/unmerged.d/ZF-908160.mdnew file mode 100644index 00000000000..94e54773dac--- /dev/null+++ b/api_docs/unmerged.d/ZF-908160.md@@ -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.diff --git a/web/src/message_events.ts b/web/src/message_events.tsindex 782c5e2480f..00945eca343 100644--- a/web/src/message_events.ts+++ b/web/src/message_events.ts@@ -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 &&diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.pyindex a6ad80cd7ee..230658575d0 100644--- a/zerver/actions/message_edit.py+++ b/zerver/actions/message_edit.py@@ -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 getdiff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 3542b292cd5..91bf881b341 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -2473,8 +2473,8 @@ paths:items:type: integerdescription: |- 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 nochannel or topic changes to apply.@@ -2492,6 +2492,9 @@ paths:Content changes should be applied only to the single messageindicated by `message_id`.++ **Changes**: Before Zulip 11.0 (feature level ZF-908160), this list+ was not guaranteed to be sorted.flags:type: arraydescription: |@@ -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,diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex c6a9453e4be..e29eab122ec 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -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.