From ceebd2e8d0e0e79f70bf838b63656b995d8bfa45 Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Wed, 25 Oct 2023 10:05:15 +0000 Subject: [PATCH] [FIX] mail: reorder direct message when opening a new one Before this PR, newly created direct message would be added at the bottom of the list instead of the top. This PR fix the issues by sorting the direct messages when creating a new direct message channel. Task-3566728 closes odoo/odoo#139960 X-original-commit: 60cf880102615a524f2fa89c71be7f1b08d931d1 Signed-off-by: Didier Debondt (did) --- .../static/src/core/common/thread_service.js | 4 +- .../static/tests/discuss_app/discuss_tests.js | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) 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" }] + }); +});