From 138c61afd14b95229656f7b3aae0a6b59d3b5b2b Mon Sep 17 00:00:00 2001 From: "Simon Goffaux (sigo)" Date: Thu, 24 Aug 2023 13:17:38 +0000 Subject: [PATCH] [FIX] mail: Opening hidden chat window should swap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we have more chat windows open than can be shown on screen, they get hidden. When we try to open one of the hidden chat windows from the messaging menu of the system tray, the chat window will unfold in the hidden menu. This commit fixes this issue by swapping the hidden chat window that is being opened with the last visible chat window. opw-3478264 closes odoo/odoo#133128 X-original-commit: 3649d3c0ba5a8999264b9746cfac0d9a4d1cc061 Signed-off-by: Alexandre Kühn (aku) --- .../src/core/common/chat_window_service.js | 3 ++ .../tests/chat_window/chat_window_tests.js | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/addons/mail/static/src/core/common/chat_window_service.js b/addons/mail/static/src/core/common/chat_window_service.js index 6fca4a347c9..d1abe2a0f3d 100644 --- a/addons/mail/static/src/core/common/chat_window_service.js +++ b/addons/mail/static/src/core/common/chat_window_service.js @@ -118,6 +118,9 @@ export class ChatWindowService { ); return this.store.chatWindows[index]; // return reactive version } + if (chatWindow.hidden) { + this.makeVisible(chatWindow); + } assignDefined(chatWindow, data); return chatWindow; } diff --git a/addons/mail/static/tests/chat_window/chat_window_tests.js b/addons/mail/static/tests/chat_window/chat_window_tests.js index e0e20cd133d..221bc310048 100644 --- a/addons/mail/static/tests/chat_window/chat_window_tests.js +++ b/addons/mail/static/tests/chat_window/chat_window_tests.js @@ -465,6 +465,38 @@ QUnit.test("closing hidden chat window", async (assert) => { await contains(":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_4)"); }); +QUnit.test("Opening hidden chat window from messaging menu", async (assert) => { + const pyEnv = await startServer(); + pyEnv["discuss.channel"].create([{ name: "Ch_1" }, { name: "Ch_2" }, { name: "Ch_3" }]); + patchUiSize({ width: 900 }); + assert.ok( + CHAT_WINDOW_END_GAP_WIDTH * 2 + CHAT_WINDOW_WIDTH * 2 + CHAT_WINDOW_INBETWEEN_WIDTH < 900, + "should have enough space to open 2 chat windows simultaneously" + ); + assert.ok( + CHAT_WINDOW_END_GAP_WIDTH * 2 + CHAT_WINDOW_WIDTH * 3 + CHAT_WINDOW_INBETWEEN_WIDTH * 2 > + 900, + "should not have enough space to open 3 chat windows simultaneously" + ); + await start(); + await click("i[aria-label='Messages']"); + await click(".o-mail-NotificationItem:contains(Ch_1)"); + await click("i[aria-label='Messages']"); + await click(".o-mail-NotificationItem:contains(Ch_2)"); + await click("i[aria-label='Messages']"); + await click(".o-mail-NotificationItem:contains(Ch_3)"); + await click(".o-mail-ChatWindowHiddenToggler"); + await contains(":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_1)"); + await contains(".o-mail-ChatWindowHiddenMenu .o-mail-ChatWindow:contains(Ch_2)"); + await contains(":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_3)"); + await click("i[aria-label='Messages']"); + await click(".o-mail-NotificationItem:contains(Ch_2)"); + await click(".o-mail-ChatWindowHiddenToggler"); + await contains(":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_1)"); + await contains(":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_2)"); + await contains(".o-mail-ChatWindowHiddenMenu .o-mail-ChatWindow:contains(Ch_3)"); +}); + QUnit.test( "focus next visible chat window when closing current chat window with ESCAPE [REQUIRE FOCUS]", async (assert) => {