[FIX] im_livechat: error when loading a page with outdated guest

This PR fixes two issues:
- Incorrect write on `channel_member_ids` (trying to link guest instead
of channel member)
- Incorrect condition in  `livechatService.leaveSession` that relies on
the live chat to be initialized while it can acutally be called before
if the current session is outdated.

This could result in server errors in the following scenario:
- Open a live chat
- Log in
- Open a live chat from the website app
- Log out
- Reload the page

Part-of: odoo/odoo#137834
This commit is contained in:
tsm-odoo
2023-10-16 12:00:02 +00:00
parent 33f7fdf5d5
commit 74cc99f72c
2 changed files with 2 additions and 3 deletions
@@ -91,7 +91,6 @@ export class LivechatService {
(this.sessionCookie && visitorUid !== userId)
) {
this.leaveSession();
this.state = SESSION_STATE.NONE;
}
browser.localStorage.setItem(ODOO_VERSION_KEY, currOdooVersion);
}
@@ -132,7 +131,7 @@ export class LivechatService {
async leaveSession({ notifyServer = true } = {}) {
const session = JSON.parse(cookie.get(this.SESSION_COOKIE) ?? "{}");
try {
if (this.state === SESSION_STATE.PERSISTED && notifyServer) {
if (session?.uuid && notifyServer) {
this.busService.deleteChannel(session.uuid);
await this.rpc("/im_livechat/visitor_leave_session", { uuid: session.uuid });
}
+1 -1
View File
@@ -54,7 +54,7 @@ class Website(models.Model):
# linked to another guest in the meantime. We need to
# update the channel to link it to the current guest.
channel_guest_member = chat_request_channel.channel_member_ids.filtered(lambda m: m.guest_id == current_guest)
chat_request_channel.write({'channel_member_ids': [Command.unlink(channel_guest_member), Command.link(current_guest)]})
chat_request_channel.write({'channel_member_ids': [Command.unlink(channel_guest_member), Command.create({'guest_id': current_guest.id})]})
if not current_guest:
channel_guest._set_auth_cookie()
return {