diff --git a/addons/mail/static/src/core/common/thread_service.js b/addons/mail/static/src/core/common/thread_service.js index 04f4f2138cb..7eb371c93cc 100644 --- a/addons/mail/static/src/core/common/thread_service.js +++ b/addons/mail/static/src/core/common/thread_service.js @@ -546,11 +546,13 @@ export class ThreadService { const data = await this.orm.call("discuss.channel", "channel_get", [], { partners_to: [id], }); - return this.store.Thread.insert({ + const thread = this.store.Thread.insert({ ...data, model: "discuss.channel", type: "chat", }); + this.sortChannels(); + return thread; } executeCommand(thread, command, body = "") { diff --git a/addons/mail/static/tests/discuss_app/discuss_tests.js b/addons/mail/static/tests/discuss_app/discuss_tests.js index 21eb3f09a36..7765ddc0483 100644 --- a/addons/mail/static/tests/discuss_app/discuss_tests.js +++ b/addons/mail/static/tests/discuss_app/discuss_tests.js @@ -1918,3 +1918,42 @@ QUnit.test("Notification settings: mute/unmute channel works correctly", async ( await click("[title='Notification Settings']"); await contains("span", { text: "Unmute Channel" }); }); + +QUnit.test("Newly created chat should be at the top of the direct message list", async () => { + const pyEnv = await startServer(); + const [userId1, userId2] = pyEnv["res.users"].create([ + { name: "Jerry Golay" }, + { name: "Albert" } + ]); + const [partnerId1] = pyEnv["res.partner"].create([ + { + name: "Albert", + user_ids: [userId2], + }, + { + name: "Jerry Golay", + user_ids: [userId1], + } + ]); + pyEnv["discuss.channel"].create({ + channel_member_ids: [ + Command.create({ + is_pinned: true, + last_interest_dt: "2021-01-01 10:00:00", + partner_id: pyEnv.currentPartnerId, + }), + Command.create({ partner_id: partnerId1 }), + ], + channel_type: "chat", + }); + const { openDiscuss } = await start(); + await openDiscuss(); + await click(".o-mail-DiscussSidebarCategory-add[title='Start a conversation']"); + await insertText(".o-discuss-ChannelSelector input", "Jer"); + await click(".o-discuss-ChannelSelector-suggestion"); + await triggerHotkey("Enter"); + await contains(".o-mail-DiscussSidebar-item", { + text: "Jerry Golay", + before: [".o-mail-DiscussSidebar-item", { text: "Albert" }] + }); +});