Skip to content

A platform for community discussion. Free, open, simple.

FIX: Ensure order when moving chat messages to another channel (#21447)

Alan Guo Xiang Tan9c39053d6f74
diff --git a/plugins/chat/lib/chat/message_mover.rb b/plugins/chat/lib/chat/message_mover.rb
index 03fc0be7013..9103b2bf832 100644
--- a/plugins/chat/lib/chat/message_mover.rb
+++ b/plugins/chat/lib/chat/message_mover.rb
@@ -111,6 +111,7 @@ module Chat
message_ids: @ordered_source_message_ids,
destination_channel_id: destination_channel.id,
}
+
moved_message_ids = DB.query_single(<<~SQL, query_args)
INSERT INTO chat_messages(
chat_channel_id, user_id, last_editor_id, message, cooked, cooked_version, created_at, updated_at
@@ -125,6 +126,7 @@ module Chat
CLOCK_TIMESTAMP()
FROM chat_messages
WHERE id IN (:message_ids)
+ ORDER BY created_at ASC, id ASC
RETURNING id
SQL