[FIX] mail: do not fold chat window when hiding it

Currently, a chat window is folded when hidden and the server is
notified. This is incorrect and leads to useless rpc calls/undesirable
fold state. A chat window is only hidden when space is lacking to display
them all. Only a user interaction should be able to fold a chat window.

Since folding the chat window when hidden is an implementation detail
only used to show the chat window header in the hidden windows dropdown,
this PR removes this behavior and adapt the hidden windows menu to
achieve the same result.

Steps to reproduce the issue:
- Go to Odoo, resize your browser so that it can only fit 2 chat windows.
- Open two chat windows, server is notified twice: so far so good.
- Open another chat window: server is notified twice: this is not correct,
the server should only be notified of the newly opened chat window.
- Reload the page: the server is notified once for each window not fitting
in the screen, this is incorrect as well.

task-3600480

closes odoo/odoo#143438

X-original-commit: 27f09bfc5049b1350b7e940a7beef92f63799771
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit is contained in:
tsm-odoo
2023-11-24 06:53:36 +00:00
parent c3cca02ac8
commit 999277cafb
4 changed files with 46 additions and 11 deletions
@@ -6,7 +6,7 @@
t-att-style="style"
t-att-class="{
'w-100 h-100 o-mobile': ui.isSmall,
'o-folded': props.chatWindow.folded,
'o-folded': props.chatWindow.folded or props.chatWindow.hidden,
'position-fixed bottom-0 overflow-hidden d-flex flex-column': !props.chatWindow.hidden,
'rounded-top-3': !props.chatWindow.hidden and !ui.isSmall,
}"
@@ -54,7 +54,7 @@
<t t-set="itemClass" t-value="'me-1'"/>
</t>
</div>
<div t-if="!props.chatWindow.folded or ui.isSmall" class="bg-view d-flex flex-column h-100 overflow-auto position-relative" t-ref="content">
<div t-if="!props.chatWindow.folded and !props.chatWindow.hidden or ui.isSmall" class="bg-view d-flex flex-column h-100 overflow-auto position-relative" t-ref="content">
<t t-if="thread" name="thread content">
<div t-if="threadActions.activeAction?.componentCondition" class="h-100" t-attf-class="{{ threadActions.activeAction.panelOuterClass }}">
<t t-component="threadActions.activeAction.component" t-props="{ ...threadActions.activeAction.componentProps, thread }"/>
@@ -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 = {}) {
@@ -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);
@@ -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([]);
});