From a8ce2886be2e02315fa3526257a941c91c5385b9 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Wed, 31 Jul 2019 14:42:35 +0000 Subject: [PATCH] [FIX] im_livechat : avoid to send twice first operator message to visitor What was going on here is that when the operator start the discussion with the visitor and the visitor navigates to a new page, the livechat button widget checks the cookie and see there is already a active conversation. It loads the mail_channel and write all the history of the conversation. So the first message is writting a first time. Then, it handles the notifications. As the visitor did not receive the first message notification yet, the first message notification comes up and the widget handle it. Adding the message a second time. To avoid this, we just stop the notification handling if the message is already present in the conversation. Task ID: 2028059 PR #34624 --- addons/im_livechat/static/src/js/im_livechat.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/im_livechat/static/src/js/im_livechat.js b/addons/im_livechat/static/src/js/im_livechat.js index 44c7dad0f05..596357ef3d4 100644 --- a/addons/im_livechat/static/src/js/im_livechat.js +++ b/addons/im_livechat/static/src/js/im_livechat.js @@ -178,6 +178,11 @@ var LivechatButton = Widget.extend({ this._livechat.unregisterTyping({ partnerID: partnerID }); } } else { // normal message + // If message from notif is already in chatter messages, stop handling + if (this._messages.some(message => message.getID() === notification[1].id)) { + this._livechat.unregisterTyping({ partnerID: notification[1].author_id[0] }); + return; + } this._addMessage(notification[1]); this._renderMessages(); if (this._chatWindow.isFolded() || !this._chatWindow.isAtBottom()) {