# 将聊天消息移动到新频道导致它们全部混乱

**URL:** <https://meta.discourse.org/t/moving-chat-messages-to-a-new-channel-jumbled-them-all-up/227301>\
**Category:** Bug\
**Tags:** chat\
**Created:** [2022 年5 月 17 日 10:33 UTC](https://meta.discourse.org/t/moving-chat-messages-to-a-new-channel-jumbled-them-all-up/227301 "2022-05-17T10:33:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

作者： ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)\
发布日期： [2022 年5 月 23 日 01:57 UTC](https://meta.discourse.org/t/moving-chat-messages-to-a-new-channel-jumbled-them-all-up/227301/4 "2022-05-23T01:57:28Z")

</div>

感谢您报告此问题，我尝试在功能中考虑到了这一点，但我认为我测试得太侥幸了 😅 所以我们确实在这里将所有时间戳设置为相同的值：

> <https://github.com/discourse/discourse-chat/blob/82c0ee7f1069bd04509c8eb15870d9165eab101a/lib/message_mover.rb#L87-L94>

问题在于我们不希望将移动的消息插入到现有频道消息之间，并且移动的消息越多，这个问题就越难解决。

在我深入研究这个问题之前，我想问一下——您能回忆并确定哪些消息放错位置了吗？只有几条，还是完全乱序了？我认为可能导致这种差异的原因是，当我们按 ID 顺序获取频道消息时（我们通常按 DESC 排序，然后反转）：

> <https://github.com/discourse/discourse-chat/blob/82c0ee7f1069bd04509c8eb15870d9165eab101a/app/controllers/chat_controller.rb#L177-L187>

> <https://github.com/discourse/discourse-chat/blob/82c0ee7f1069bd04509c8eb15870d9165eab101a/app/controllers/chat_controller.rb#L201-L203>

而在消息移动器中，我按 `created_at` 排序以保持顺序，这可能会导致一些小的差异：

> <https://github.com/discourse/discourse-chat/blob/82c0ee7f1069bd04509c8eb15870d9165eab101a/lib/message_mover.rb#L59-L61>

我有一些关于如何解决这个问题的想法（也许更改消息移动器以按 ID 排序或更改控制器以按 `created_at` 排序就足够了，我更倾向于后者，因为它更有意义），但如果可能的话，我想了解一下顺序混乱的程度。

---

_[View the full topic](https://meta.discourse.org/t/moving-chat-messages-to-a-new-channel-jumbled-them-all-up/227301)._
