From 957d57dd7f364572f2ecc602f4b295dba734caa6 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Mon, 20 Nov 2023 15:08:37 +0100 Subject: [PATCH] [FIX] im_livechat, *: do not allow reactions on temporary threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the "add reaction" button was available even when the thread is not persisted. This is wrong since those messages are only temporary thus not known by the server: a crash would occur when trying to add a reaction to such messages. This commit disables reactions for temporary messages. Steps to reproduce the issue: - Go to the `/contactus` page - Open a chat with the welcome bot - Try to add a reaction to its first message - An error modal appears task-3603577 closes odoo/odoo#142718 Signed-off-by: Alexandre Kühn (aku) --- .../static/src/embed/common/message_patch.js | 17 +++++++++++++ .../tours/website_livechat_chatbot_flow.js | 24 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/addons/im_livechat/static/src/embed/common/message_patch.js b/addons/im_livechat/static/src/embed/common/message_patch.js index be08238adbe..604f2efcf92 100644 --- a/addons/im_livechat/static/src/embed/common/message_patch.js +++ b/addons/im_livechat/static/src/embed/common/message_patch.js @@ -4,6 +4,7 @@ import { Message } from "@mail/core/common/message"; import { patch } from "@web/core/utils/patch"; import { url } from "@web/core/utils/urls"; +import { SESSION_STATE } from "./livechat_service"; Message.props.push("isTypingMessage?"); @@ -17,6 +18,22 @@ patch(Message.prototype, { return this.props.thread?.type === "livechat" ? 2 : super.quickActionCount; }, + get canAddReaction() { + return ( + super.canAddReaction && + (this.props.thread?.type !== "livechat" || + this.env.services["im_livechat.livechat"].state === SESSION_STATE.PERSISTED) + ); + }, + + get canReplyTo() { + return ( + super.canReplyTo && + (this.props.thread?.type !== "livechat" || + this.env.services["im_livechat.chatbot"].inputEnabled) + ); + }, + /** * @param {import("@im_livechat/embed/common/chatbot/chatbot_step_model").StepAnswer} answer */ diff --git a/addons/website_livechat/static/tests/tours/website_livechat_chatbot_flow.js b/addons/website_livechat/static/tests/tours/website_livechat_chatbot_flow.js index ab41f3cc946..0c1c768f4c3 100644 --- a/addons/website_livechat/static/tests/tours/website_livechat_chatbot_flow.js +++ b/addons/website_livechat/static/tests/tours/website_livechat_chatbot_flow.js @@ -26,7 +26,17 @@ registry.category("web_tour.tours").add("website_livechat_chatbot_flow_tour", { }, { trigger: messagesContain("How can I help you?"), - run: () => {}, // check question_selection message is posted + // check question_selection message is posted and reactions are not + // available since the thread is not yet persisted + run() { + if ( + this.$anchor[0].querySelector( + ".o-mail-Message-actions [title='Add a Reaction']" + ) + ) { + console.error("Reactions should not be available before thread is persisted."); + } + }, }, { trigger: 'li:contains("I want to buy the software")', @@ -34,7 +44,17 @@ registry.category("web_tour.tours").add("website_livechat_chatbot_flow_tour", { }, { trigger: messagesContain("I want to buy the software"), - run: () => {}, // check selected option is posted + // check selected option is posted and reactions are available since + // the thread has been persisted in the process + run() { + if ( + !this.$anchor[0].querySelector( + ".o-mail-Message-actions [title='Add a Reaction']" + ) + ) { + console.error("Reactions should be available since thread is persisted."); + } + }, }, { trigger: messagesContain("Can you give us your email please?"),