From d6dddb95181b6af66ef3ed8bb5246702cdf34a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 5 Jul 2023 17:05:55 +0000 Subject: [PATCH] [FIX] mail: do not open server-synced chat windows in mobile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when there were some chat windows open in desktop, mobile device were displaying the chat windows at page load. This was even buggy, because the chat windows are mounted in a folded state, and it shows only the header of chat window. The content behind the chat window is visible but we cannot interact unless the chat window is closed. This commit makes a few changes to fix the issue: - Folded state of chat windows is ignored in mobile: the chat window is fully displayed in mobile even when in "folded" state. - At page load, server data from chat window state are ignored in mobile - Messaging menu in mobile should not display content below: dropdown in mobile had some margin which displayed some content below. Fix is to have `m-0`. - Chat Windows are displayed on top of Messaging Menu in mobile. In desktop it makes sense it's the other way, because messaging menu can be toggled when there's a chat window. But it's not clickable in mobile, and it acts as the previous screen to open a chat window. closes odoo/odoo#127597 X-original-commit: 791924d6d1d0e5aff6d9e84844626ac5863c2a88 Signed-off-by: Didier Debondt (did) Signed-off-by: Alexandre Kühn (aku) --- .../static/src/core/common/chat_window.scss | 3 ++ .../static/src/core/common/chat_window.xml | 4 +-- .../static/src/core/web/messaging_menu.xml | 2 +- .../src/core/web/messaging_service_patch.js | 4 +-- .../tests/chat_window/chat_window_tests.js | 29 +++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/addons/mail/static/src/core/common/chat_window.scss b/addons/mail/static/src/core/common/chat_window.scss index cccb2eb74ab..d1fcdec3d74 100644 --- a/addons/mail/static/src/core/common/chat_window.scss +++ b/addons/mail/static/src/core/common/chat_window.scss @@ -2,6 +2,9 @@ height: 480px; width: $o-mail-ChatWindow-width; z-index: 999; // messaging menu is dropdown (1000) + &.o-mobile { + z-index: 1001; // above messaging menu (chat window takes whole screen) + } box-shadow: -5px -5px 10px rgba(#000000, 0.09); outline: none; diff --git a/addons/mail/static/src/core/common/chat_window.xml b/addons/mail/static/src/core/common/chat_window.xml index 24859b7a496..792da3b6f90 100644 --- a/addons/mail/static/src/core/common/chat_window.xml +++ b/addons/mail/static/src/core/common/chat_window.xml @@ -5,7 +5,7 @@
-
+
diff --git a/addons/mail/static/src/core/web/messaging_menu.xml b/addons/mail/static/src/core/web/messaging_menu.xml index 22d59c16b82..15f02d4605d 100644 --- a/addons/mail/static/src/core/web/messaging_menu.xml +++ b/addons/mail/static/src/core/web/messaging_menu.xml @@ -2,7 +2,7 @@ - + diff --git a/addons/mail/static/src/core/web/messaging_service_patch.js b/addons/mail/static/src/core/web/messaging_service_patch.js index 79abc7c57fc..9025f0d1b66 100644 --- a/addons/mail/static/src/core/web/messaging_service_patch.js +++ b/addons/mail/static/src/core/web/messaging_service_patch.js @@ -23,7 +23,7 @@ patch(Messaging.prototype, "mail/core/web", { ); this.notificationService.add(notification, { type: "info" }); const chat = await this.threadService.getChat({ partnerId }); - if (chat) { + if (chat && !this.ui.isSmall) { this.chatWindowService.insert({ thread: chat }); } }); @@ -32,7 +32,7 @@ patch(Messaging.prototype, "mail/core/web", { this.loadFailures(); for (const channelData of data.channels) { const thread = this.threadService.createChannelThread(channelData); - if (channelData.is_minimized && channelData.state !== "closed") { + if (channelData.is_minimized && channelData.state !== "closed" && !this.ui.isSmall) { this.chatWindowService.insert({ autofocus: 0, folded: channelData.state === "folded", 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 75e85c41fd8..67bbac9bd13 100644 --- a/addons/mail/static/tests/chat_window/chat_window_tests.js +++ b/addons/mail/static/tests/chat_window/chat_window_tests.js @@ -1007,6 +1007,35 @@ QUnit.test("Chat window in mobile are not foldable", async (assert) => { assert.containsOnce($, ".o-mail-ChatWindow-content"); // content => non-folded }); +QUnit.test("Server-synced chat windows should not open at page load on mobile", async (assert) => { + const pyEnv = await startServer(); + pyEnv["discuss.channel"].create({ + channel_member_ids: [ + Command.create({ + fold_state: "open", + is_minimized: true, + partner_id: pyEnv.currentPartnerId, + }), + ], + }); + patchUiSize({ size: SIZES.SM }); + await start(); + assert.containsNone($, ".o-mail-ChatWindow"); +}); + +QUnit.test("chat window of channels should not have 'Open in Discuss' (mobile)", async (assert) => { + const pyEnv = await startServer(); + pyEnv["discuss.channel"].create({ name: "General" }); + patchUiSize({ size: SIZES.SM }); + await start(); + await click(".o_menu_systray i[aria-label='Messages']"); + await click(".o-mail-NotificationItem"); + assert.containsOnce($, ".o-mail-ChatWindow"); + assert.containsOnce($, "[title='Open Actions Menu']"); + await click("[title='Open Actions Menu']"); + assert.containsNone($, "[title='Open in Discuss']"); +}); + QUnit.test("Open chat window of new inviter", async (assert) => { const pyEnv = await startServer(); await start();