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([]);
+});