From e74c93837acce3602b2f5ccc148c8dad155d0eb4 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Fri, 7 Oct 2022 11:10:33 +0000 Subject: [PATCH] [FIX] im_livechat: fix send messages on closed chat window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, sending a message on a livechat whose visitor closed the chat window would have resulted in a traceback being shown to the visitor. This was occurring when a message was sent by an operator or the welcome bot. An other related issue occurred when sending the feedback to the welcome bot. This commit fixes those issues by correctly guarding calls to `publicLivechatGlobal.chatWindow`. task-3010725 closes odoo/odoo#102752 X-original-commit: 524fc3e4cb0e63029e774e97de687998ccf06909 Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Stockbauer Matthieu (tsm) --- .../static/src/legacy/public_livechat_chatbot.js | 3 +++ addons/im_livechat/static/src/public_models/chatbot.js | 6 ++++++ .../public_livechat_global_notification_handler.js | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js b/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js index 8e3fd39fa30..7bb6e80181d 100644 --- a/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js +++ b/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js @@ -101,6 +101,9 @@ import LivechatButton from '@im_livechat/legacy/widgets/livechat_button'; this.messaging.publicLivechatGlobal.chatbot.update({ welcomeMessageTimeout: setTimeout(() => { + if (!this.messaging.publicLivechatGlobal.chatWindow || !this.messaging.publicLivechatGlobal.chatWindow.exists()) { + return; + } this._sendWelcomeChatbotMessage(stepIndex + 1, welcomeMessageDelay); this.messaging.publicLivechatGlobal.chatWindow.renderMessages(); }, welcomeMessageDelay), diff --git a/addons/im_livechat/static/src/public_models/chatbot.js b/addons/im_livechat/static/src/public_models/chatbot.js index a1f8f0432b1..d5a2ed5ed0c 100644 --- a/addons/im_livechat/static/src/public_models/chatbot.js +++ b/addons/im_livechat/static/src/public_models/chatbot.js @@ -233,6 +233,9 @@ registerModel({ this.messaging.publicLivechatGlobal.livechatButtonView.update({ isTypingTimeout: setTimeout( () => { + if (!this.messaging.publicLivechatGlobal.chatWindow || !this.messaging.publicLivechatGlobal.chatWindow.exists()) { + return; + } this.messaging.publicLivechatGlobal.chatWindow.widget.$('.o_mail_thread_content').append( $(qweb.render('im_livechat.legacy.chatbot.is_typing_message', { 'chatbotImageSrc': `/im_livechat/operator/${ @@ -253,6 +256,9 @@ registerModel({ * This will receive the next step and call step processing. */ async triggerNextStep() { + if (!this.messaging.publicLivechatGlobal.chatWindow || !this.messaging.publicLivechatGlobal.chatWindow.exists()) { + return; + } let triggerNextStep = true; if ( this.currentStep && diff --git a/addons/im_livechat/static/src/public_models/public_livechat_global_notification_handler.js b/addons/im_livechat/static/src/public_models/public_livechat_global_notification_handler.js index e96418c9634..04b4b9c3301 100644 --- a/addons/im_livechat/static/src/public_models/public_livechat_global_notification_handler.js +++ b/addons/im_livechat/static/src/public_models/public_livechat_global_notification_handler.js @@ -39,6 +39,9 @@ registerModel({ return; } case 'mail.channel.member/typing_status': { + if (!this.messaging.publicLivechatGlobal.chatWindow || !this.messaging.publicLivechatGlobal.chatWindow.exists()) { + return; + } const channelMemberData = payload; if (channelMemberData.channel.id !== this.messaging.publicLivechatGlobal.publicLivechat.id) { return; @@ -58,6 +61,9 @@ registerModel({ return; } case 'mail.channel/new_message': { + if (!this.messaging.publicLivechatGlobal.chatWindow || !this.messaging.publicLivechatGlobal.chatWindow.exists()) { + return; + } if (payload.id !== this.messaging.publicLivechatGlobal.publicLivechat.id) { return; } @@ -75,6 +81,9 @@ registerModel({ return; } case 'mail.message/insert': { + if (!this.messaging.publicLivechatGlobal.chatWindow || !this.messaging.publicLivechatGlobal.chatWindow.exists()) { + return; + } const message = this.messaging.publicLivechatGlobal.messages.find(message => message.id === payload.id); if (!message) { return;