From 4a92dfa3ba9b74c17c7ddaca1a9806e40c22e200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 24 Jul 2023 14:35:15 +0000 Subject: [PATCH] [FIX] mail: open chat on very narrow devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when opening a chat on a very narrow mobile device (e.g. 300px width), there was the following crash: ``` TypeError: Cannot set properties of undefined (setting 'hidden') ``` This happens because the computed maximum amount of visible chat windows was 0, which prevented the good opening of chat window. Indeed, the code relied on at least a `CHAT_WINDOW_WIDTH`, which is 360px. This commit fixes the issue by guaranteeing that it is always possible to make 1 chat window on the screen, regardless of the width of the device. closes odoo/odoo#129474 X-original-commit: 1c9289fffe2a8d0936a1afa99255777ff275c712 Signed-off-by: Sébastien Theys (seb) --- .../static/src/core/common/chat_window_service.js | 5 +++-- .../static/tests/chat_window/chat_window_tests.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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 5067cb16288..f4772205f73 100644 --- a/addons/mail/static/src/core/common/chat_window_service.js +++ b/addons/mail/static/src/core/common/chat_window_service.js @@ -68,8 +68,9 @@ export class ChatWindowService { : CHAT_WINDOW_END_GAP_WIDTH; const endGap = this.ui.isSmall ? 0 : CHAT_WINDOW_END_GAP_WIDTH; const available = browser.innerWidth - startGap - endGap; - const maxAmountWithoutHidden = Math.floor( - available / (CHAT_WINDOW_WIDTH + CHAT_WINDOW_INBETWEEN_WIDTH) + const maxAmountWithoutHidden = Math.max( + 1, + Math.floor(available / (CHAT_WINDOW_WIDTH + CHAT_WINDOW_INBETWEEN_WIDTH)) ); return maxAmountWithoutHidden; } 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 27b161cb45b..936998bf1d0 100644 --- a/addons/mail/static/tests/chat_window/chat_window_tests.js +++ b/addons/mail/static/tests/chat_window/chat_window_tests.js @@ -236,6 +236,17 @@ QUnit.test("chat window: open / close", async (assert) => { assert.verifySteps(["rpc:channel_fold/open"]); }); +QUnit.test("open chat on very narrow device should work", async (assert) => { + const pyEnv = await startServer(); + patchUiSize({ width: 200 }); + pyEnv["discuss.channel"].create({}); + await start(); + assert.ok(CHAT_WINDOW_WIDTH > 200, "Device is narrower than usual chat window width"); // scenario where this might fail + await click("button i[aria-label='Messages']"); + await click(".o-mail-NotificationItem"); + assert.containsOnce($, ".o-mail-ChatWindow"); +}); + QUnit.test( "Mobile: closing a chat window should not update channel state on the server", async (assert) => {