diff --git a/addons/im_livechat/static/src/legacy/public_livechat.js b/addons/im_livechat/static/src/legacy/public_livechat.js index 71332b7be10..202fc02755c 100644 --- a/addons/im_livechat/static/src/legacy/public_livechat.js +++ b/addons/im_livechat/static/src/legacy/public_livechat.js @@ -421,6 +421,7 @@ var LivechatButton = Widget.extend({ } else { this._closeChat(); } + this._visitorLeaveSession(); }, /** * @private @@ -470,6 +471,19 @@ var LivechatButton = Widget.extend({ ev.stopPropagation(); this._chatWindow.renderHeader(); }, + /** + * @private + * Called when the visitor leaves the livechat chatter the first time (first click on X button) + * this will deactivate the mail_channel, notify operator that visitor has left the channel. + */ + _visitorLeaveSession: function () { + var cookie = utils.get_cookie('im_livechat_session'); + if (cookie) { + var channel = JSON.parse(cookie); + session.rpc('/im_livechat/visitor_leave_session', {uuid: channel.uuid}); + utils.set_cookie('im_livechat_session', "", -1); // remove cookie + } + }, }); /* diff --git a/addons/website_livechat/static/src/legacy/public_livechat.js b/addons/website_livechat/static/src/legacy/public_livechat.js index ad0e984d4fd..69c274af3ab 100644 --- a/addons/website_livechat/static/src/legacy/public_livechat.js +++ b/addons/website_livechat/static/src/legacy/public_livechat.js @@ -2,7 +2,6 @@ odoo.define('website_livechat.legacy.website_livechat.livechat_request', functio "use strict"; var utils = require('web.utils'); -var session = require('web.session'); var LivechatButton = require('im_livechat.legacy.im_livechat.im_livechat').LivechatButton; const config = require('web.config'); @@ -42,26 +41,6 @@ LivechatButton.include({ }); } }, - - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - - /** - * @override - * Called when the visitor closes the livechat chatter the first time (first click on X button) - * this will deactivate the mail_channel, clean the chat request if any - * and allow the operators to send the visitor a new chat request - */ - _onCloseChatWindow: function (ev) { - this._super(ev); - var cookie = utils.get_cookie('im_livechat_session'); - if (cookie) { - var channel = JSON.parse(cookie); - session.rpc('/im_livechat/visitor_leave_session', {uuid: channel.uuid}); - utils.set_cookie('im_livechat_session', "", -1); // remove cookie - } - }, }); return {