[FIX] im_livechat, *: do not allow reactions on temporary threads

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) <aku@odoo.com>
This commit is contained in:
tsm-odoo
2023-11-21 12:56:57 +00:00
parent e87a17949f
commit 957d57dd7f
2 changed files with 39 additions and 2 deletions
@@ -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
*/
@@ -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?"),