[FIX] mail: chat window state should sync crosstab

Before this commit, chat windows state (open/close/folded) was not
syncing between browser tabs. This lack of feature makes using chat
in crosstab quite inconvenient.

This feature exist in 16.2 and was mistakenly removed from rewritting
of Discuss code in 16.3. This commit reimplements as it was in 16.2.

Task-3435120

closes odoo/odoo#129812

X-original-commit: 8f27d1f254e79becf6886cdb90a1af14b28e9946
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2023-07-27 05:18:49 +02:00
parent 8d4650e673
commit 29ca8f806a
2 changed files with 41 additions and 0 deletions
@@ -1,5 +1,6 @@
/* @odoo-module */
import { createLocalId } from "@mail/utils/common/misc";
import { reactive } from "@odoo/owl";
import { _t } from "@web/core/l10n/translation";
@@ -73,6 +74,28 @@ export class DiscussCoreWeb {
this.chatWindowService.insert({ thread: chat });
}
});
this.busService.subscribe("mail.record/insert", async (payload) => {
if (payload.Thread) {
const data = payload.Thread;
const thread = this.store.threads[createLocalId(data.model, data.id)];
if (data.serverFoldState && thread && data.serverFoldState !== thread.state) {
thread.state = data.serverFoldState;
if (thread.state === "closed") {
const chatWindow = this.store.chatWindows.find(
(chatWindow) => chatWindow.threadLocalId === thread.localId
);
if (chatWindow) {
this.chatWindowService.close(chatWindow);
}
} else {
this.chatWindowService.insert({
thread,
folded: thread.state === "folded",
});
}
}
}
});
}
}
@@ -161,6 +161,24 @@ QUnit.test("chat window: basic rendering", async (assert) => {
assert.containsOnce($, "[title='Open in Discuss']");
});
QUnit.test("Fold state of chat window is sync among browser tabs", async (assert) => {
const pyEnv = await startServer();
pyEnv["discuss.channel"].create({ name: "General" });
const tab1 = await start({ asTab: true });
const tab2 = await start({ asTab: true });
await tab1.click(".o_menu_systray i[aria-label='Messages']");
await tab1.click(".o-mail-NotificationItem");
await tab1.click(".o-mail-ChatWindow-header"); // Fold
assert.containsNone(tab1.target, ".o-mail-ChatWindow .o-mail-ChatWindow-content");
assert.containsNone(tab2.target, ".o-mail-ChatWindow .o-mail-ChatWindow-content");
await tab2.click(".o-mail-ChatWindow-header"); // Unfold
assert.containsOnce(tab1.target, ".o-mail-ChatWindow .o-mail-ChatWindow-content");
assert.containsOnce(tab2.target, ".o-mail-ChatWindow .o-mail-ChatWindow-content");
await tab1.click("[title='Close Chat Window']");
assert.containsNone(tab1.target, ".o-mail-ChatWindow");
assert.containsNone(tab2.target, ".o-mail-ChatWindow");
});
QUnit.test(
"Mobile: opening a chat window should not update channel state on the server",
async (assert) => {