From a445f36550f7f96d8f1a36d0c887dad8ab76ec2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 1 Dec 2023 16:22:25 +0100 Subject: [PATCH] [FIX] mail: make getRecentChannels order deterministic Fallback to ID compare when the dates are the same. Added some extra steps in the test to help further debugging if this PR does not completely resolve the issue. runbot-28637 Part-of: odoo/odoo#144580 --- .../src/core/web/thread_service_patch.js | 18 +++++++++--------- .../discuss/core/web/command_palette_tests.js | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/addons/mail/static/src/core/web/thread_service_patch.js b/addons/mail/static/src/core/web/thread_service_patch.js index f6edb33c841..fcd59ac561c 100644 --- a/addons/mail/static/src/core/web/thread_service_patch.js +++ b/addons/mail/static/src/core/web/thread_service_patch.js @@ -235,16 +235,16 @@ patch(ThreadService.prototype, { return Object.values(this.store.Thread.records) .filter((thread) => thread.model === "discuss.channel") .sort((a, b) => { - if (!a.lastInterestDateTime && !b.lastInterestDateTime) { - return 0; + if (a.lastInterestDateTime?.ts !== b.lastInterestDateTime?.ts) { + if (!b.lastInterestDateTime) { + return -1; + } + if (!a.lastInterestDateTime) { + return 1; + } + return b.lastInterestDateTime.ts - a.lastInterestDateTime.ts; } - if (a.lastInterestDateTime && !b.lastInterestDateTime) { - return -1; - } - if (!a.lastInterestDateTime && b.lastInterestDateTime) { - return 1; - } - return b.lastInterestDateTime.ts - a.lastInterestDateTime.ts; + return a.id - b.id; }); }, getNeedactionChannels() { diff --git a/addons/mail/static/tests/discuss/core/web/command_palette_tests.js b/addons/mail/static/tests/discuss/core/web/command_palette_tests.js index daa2b0e8dc3..a1a490d61fa 100644 --- a/addons/mail/static/tests/discuss/core/web/command_palette_tests.js +++ b/addons/mail/static/tests/discuss/core/web/command_palette_tests.js @@ -43,6 +43,8 @@ QUnit.test("open the chatWindow of a channel from the command palette", async () await insertText(".o_command_palette_search input", "#"); advanceTime(commandSetupRegistry.get("#").debounceDelay); await contains(".o_command", { count: 2 }); + await contains(".o_command", { text: "general", before: [".o_command", { text: "project" }] }); + await contains(".o_command.focused"); await click(".o_command.focused", { text: "general" }); await contains(".o-mail-ChatWindow", { text: "general" }); });