From 999277cafba7bbdb3e874529e4dc29f3f0ff6d37 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Fri, 24 Nov 2023 06:54:29 +0100 Subject: [PATCH] [FIX] mail: do not fold chat window when hiding it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, a chat window is folded when hidden and the server is notified. This is incorrect and leads to useless rpc calls/undesirable fold state. A chat window is only hidden when space is lacking to display them all. Only a user interaction should be able to fold a chat window. Since folding the chat window when hidden is an implementation detail only used to show the chat window header in the hidden windows dropdown, this PR removes this behavior and adapt the hidden windows menu to achieve the same result. Steps to reproduce the issue: - Go to Odoo, resize your browser so that it can only fit 2 chat windows. - Open two chat windows, server is notified twice: so far so good. - Open another chat window: server is notified twice: this is not correct, the server should only be notified of the newly opened chat window. - Reload the page: the server is notified once for each window not fitting in the screen, this is incorrect as well. task-3600480 closes odoo/odoo#143438 X-original-commit: 27f09bfc5049b1350b7e940a7beef92f63799771 Signed-off-by: Sébastien Theys (seb) Signed-off-by: Matthieu Stockbauer (tsm) --- .../static/src/core/common/chat_window.xml | 4 +- .../src/core/common/chat_window_service.js | 4 +- .../core/web/chat_window_service_patch.js | 10 ++--- .../tests/chat_window/chat_window_tests.js | 39 +++++++++++++++++++ 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/addons/mail/static/src/core/common/chat_window.xml b/addons/mail/static/src/core/common/chat_window.xml index 364e94344d3..d5f792f5d7c 100644 --- a/addons/mail/static/src/core/common/chat_window.xml +++ b/addons/mail/static/src/core/common/chat_window.xml @@ -6,7 +6,7 @@ t-att-style="style" t-att-class="{ 'w-100 h-100 o-mobile': ui.isSmall, - 'o-folded': props.chatWindow.folded, + 'o-folded': props.chatWindow.folded or props.chatWindow.hidden, 'position-fixed bottom-0 overflow-hidden d-flex flex-column': !props.chatWindow.hidden, 'rounded-top-3': !props.chatWindow.hidden and !ui.isSmall, }" @@ -54,7 +54,7 @@ -
+
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 27d1453e3a2..d2c33f53782 100644 --- a/addons/mail/static/src/core/common/chat_window_service.js +++ b/addons/mail/static/src/core/common/chat_window_service.js @@ -86,7 +86,7 @@ export class ChatWindowService { makeVisible(chatWindow) { const swaped = this.visible[this.visible.length - 1]; this.hide(swaped); - this.show(chatWindow); + this.show(chatWindow, { notifyState: false }); } toggleFold(chatWindow) { @@ -105,8 +105,6 @@ export class ChatWindowService { hide(chatWindow) { chatWindow.hidden = true; - chatWindow.folded = true; - chatWindow.thread.state = "folded"; } async close(chatWindow, options = {}) { diff --git a/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js b/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js index f9d816698b9..2ea89e52412 100644 --- a/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js +++ b/addons/mail/static/src/discuss/core/web/chat_window_service_patch.js @@ -12,10 +12,6 @@ patch(ChatWindowService.prototype, { this.notifyState(chatWindow); } }, - hide(chatWindow) { - super.hide(...arguments); - this.notifyState(chatWindow); - }, notifyState(chatWindow) { if (this.ui.isSmall) { return; @@ -37,9 +33,11 @@ patch(ChatWindowService.prototype, { const chatWindow = super.open(...arguments); this.notifyState(chatWindow); }, - show(chatWindow) { + show(chatWindow, { notifyState = true } = {}) { super.show(...arguments); - this.notifyState(chatWindow); + if (notifyState) { + this.notifyState(chatWindow); + } }, toggleFold(chatWindow) { super.toggleFold(...arguments); 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 80ffca3b5ca..12ecf28c82f 100644 --- a/addons/mail/static/tests/chat_window/chat_window_tests.js +++ b/addons/mail/static/tests/chat_window/chat_window_tests.js @@ -1195,3 +1195,42 @@ QUnit.test( await contains(".o-mail-ChatWindow"); } ); + +QUnit.test("hiding/swapping hidden chat windows does not update server state", async (assert) => { + patchUiSize({ size: SIZES.MD }); // only 2 chat window can be opened at a time + const pyEnv = await startServer(); + pyEnv["discuss.channel"].create([{ name: "General" }, { name: "Sales" }, { name: "D&D" }]); + await start({ + mockRPC(route, args) { + if (args.method === "channel_fold") { + const [channel] = pyEnv["discuss.channel"].searchRead([ + ["id", "=", args.args[0][0]], + ]); + assert.step(`${channel.name} - ${args.kwargs.state}`); + } + }, + }); + await click(".o_menu_systray i[aria-label='Messages']"); + await click(".o-mail-NotificationItem", { text: "General" }); + await contains(".o-mail-ChatWindow", { text: "General" }); + assert.verifySteps(["General - open"]); + await click(".o_menu_systray i[aria-label='Messages']"); + await click(".o-mail-NotificationItem", { text: "Sales" }); + await contains(".o-mail-ChatWindow", { text: "Sales" }); + assert.verifySteps(["Sales - open"]); + // Sales chat window will be hidden since there is not enough space for the + // D&D one but Sales fold state should not be updated. + await click(".o_menu_systray i[aria-label='Messages']"); + await click(".o-mail-NotificationItem", { text: "D&D" }); + await contains(".o-mail-ChatWindow", { text: "D&D" }); + assert.verifySteps(["D&D - open"]); + // D&D chat window will be hidden since there is not enough space for the + // Sales one, the server should not be notified as the state is up to date. + await click(".o-mail-ChatWindowHiddenToggler"); + await click(".o-mail-ChatWindowHiddenMenu-item .o-mail-ChatWindow-header", { + text: "Sales", + visible: true, + }); + await contains(".o-mail-ChatWindow", { text: "Sales" }); + assert.verifySteps([]); +});