[FIX] im_livechat: fix livechat session state

Before this commit, the fold state, seen message id and message unread counter
was never saved on the livechat session state. This is due to an incorrect check
on the session state. We wan't to ensure the session is not closed when writing
such information but the state was checked on the thread instead of the livechat
service.

closes odoo/odoo#131049

X-original-commit: a81208d980a2a30bcff6382729e2ed8369e6a65d
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-08-07 19:58:19 +02:00
parent 12f004f281
commit 7fcf33189e
2 changed files with 35 additions and 3 deletions
@@ -133,17 +133,23 @@ patch(ThreadService.prototype, {
});
}
onChange(thread, "state", () => {
if ([SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(thread.state)) {
if (
![SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(this.livechatService.state)
) {
this.livechatService.updateSession({ state: thread.state });
}
});
onChange(thread, "seen_message_id", () => {
if ([SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(thread.state)) {
if (
![SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(this.livechatService.state)
) {
this.livechatService.updateSession({ seen_message_id: thread.seen_message_id });
}
});
onChange(thread, "message_unread_counter", () => {
if ([SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(thread.state)) {
if (
![SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(this.livechatService.state)
) {
this.livechatService.updateSession({ channel: thread.channel });
}
});
@@ -62,3 +62,29 @@ QUnit.test("Session is reset after failing to persist the channel", async (asser
await click(".o-livechat-LivechatButton");
assert.containsOnce($, ".o-mail-ChatWindow");
});
QUnit.test("Thread state is saved on the session", async (assert) => {
await startServer();
await loadDefaultConfig();
const env = await start();
await click(".o-livechat-LivechatButton");
assert.strictEqual(env.services["im_livechat.livechat"].sessionCookie.state, "open");
await click(".o-mail-ChatWindow-header");
assert.strictEqual(env.services["im_livechat.livechat"].sessionCookie.state, "folded");
await click(".o-mail-ChatWindow-header");
assert.strictEqual(env.services["im_livechat.livechat"].sessionCookie.state, "open");
});
QUnit.test("Seen message is saved on the session", async (assert) => {
await startServer();
await loadDefaultConfig();
const env = await start();
await click(".o-livechat-LivechatButton");
assert.notOk(env.services["im_livechat.livechat"].sessionCookie.seen_message_id);
await insertText(".o-mail-Composer-input", "Hello World!");
await afterNextRender(() => triggerHotkey("Enter"));
assert.strictEqual(
env.services["im_livechat.livechat"].sessionCookie.seen_message_id,
env.services["im_livechat.livechat"].thread.seenInfos[0].lastSeenMessage.id
);
});