[FIX] mail: closing hidden chat window should not crash

Before this commit, closing a hidden chat window may crash.

This happens because closing a chat window was always treated as the
closing of a visible chat window, which should make the 1st hidden
chat window visible, if any. This code should not be called when
closing a hidden chat window, otherwise unexpected behaviour are
to be expected, e.g. closing 2nd hidden chat window swaps last visible
with 1st hidden chat window, or even a crash.

This commit makes sure auto-swapping of 1st hidden chat window only
occurs when closing a visible chat window.

opw-3460466

closes odoo/odoo#132458

X-original-commit: b49364b687757385a2a7356d17dc428edafd2767
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
lrizzi1
2023-08-20 14:43:56 +02:00
committed by Alexandre Kühn
parent cd887a8289
commit 698e14a003
3 changed files with 41 additions and 2 deletions
@@ -13,7 +13,7 @@
</t>
<t t-name="mail.ChatWindowHiddenMenu">
<Dropdown position="'top-end'" menuClass="'p-0'" togglerClass="'o-mail-ChatWindowHiddenToggler btn d-flex align-items-center rounded-top-3 bg-900'">
<Dropdown position="'top-end'" menuClass="'o-mail-ChatWindowHiddenMenu p-0'" togglerClass="'o-mail-ChatWindowHiddenToggler btn d-flex align-items-center rounded-top-3 bg-900'">
<t t-set-slot="toggler">
<div class="me-1 fa fa-comments-o"/>
<div class="mx-1 text-truncate" t-esc="chatWindowService.hidden.length"/>
@@ -153,7 +153,7 @@ export class ChatWindowService {
}
close(chatWindow, { escape = false } = {}) {
if (this.maxVisible < this.store.chatWindows.length) {
if (!chatWindow.hidden && this.maxVisible < this.store.chatWindows.length) {
const swaped = this.hidden[0];
swaped.hidden = false;
swaped.folded = false;
@@ -430,6 +430,45 @@ QUnit.test("open 3 different chat windows: not enough screen width", async (asse
);
});
QUnit.test("closing hidden chat window", async (assert) => {
const pyEnv = await startServer();
pyEnv["discuss.channel"].create([
{ name: "Ch_1" },
{ name: "Ch_2" },
{ name: "Ch_3" },
{ name: "Ch_4" },
]);
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("i[aria-label='Messages']");
await click(".o-mail-NotificationItem:contains(Ch_4)");
await click(".o-mail-ChatWindowHiddenToggler");
assert.containsOnce($, ":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_1)");
assert.containsOnce($, ".o-mail-ChatWindowHiddenMenu .o-mail-ChatWindow:contains(Ch_2)");
assert.containsOnce($, ".o-mail-ChatWindowHiddenMenu .o-mail-ChatWindow:contains(Ch_3)");
assert.containsOnce($, ":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_4)");
await click(".o-mail-ChatWindow:contains(Ch_2) [title='Close Chat Window']");
assert.containsOnce($, ":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_1)");
assert.containsNone($, ".o-mail-ChatWindow:contains(Ch_2)");
assert.containsOnce($, ".o-mail-ChatWindowHiddenMenu .o-mail-ChatWindow:contains(Ch_3)");
assert.containsOnce($, ":not(.o-mail-ChatWindowHiddenMenu) .o-mail-ChatWindow:contains(Ch_4)");
});
QUnit.test(
"focus next visible chat window when closing current chat window with ESCAPE [REQUIRE FOCUS]",
async (assert) => {