[FIX] im_livechat, *: fix chat requests from operator
*: mail, website_livechat. This PR fixes two issues with the live chat requests when initiated by the operator: - Thread name should not include "website" since [1] - Welcome message should not be shown when the operator is the one who initiated the chat [1]: https://github.com/odoo/odoo/pull/125931 closes odoo/odoo#132815 X-original-commit: 38a6658beec8bd4423ee8b4ac16f2592b9fb36ff Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -47,6 +47,7 @@ class Website(models.Model):
|
||||
return {
|
||||
"folded": False,
|
||||
"id": chat_request_channel.id,
|
||||
"requested_by_operator": chat_request_channel.create_uid in chat_request_channel.livechat_operator_id.user_ids,
|
||||
"operator_pid": [
|
||||
chat_request_channel.livechat_operator_id.id,
|
||||
chat_request_channel.livechat_operator_id.user_livechat_username or chat_request_channel.livechat_operator_id.display_name,
|
||||
|
||||
@@ -64,7 +64,7 @@ class WebsiteVisitor(models.Model):
|
||||
for visitor in self:
|
||||
operator = self.env.user
|
||||
country = visitor.country_id
|
||||
visitor_name = "%s (%s)" % (visitor.display_name, country.name) if country else visitor.display_name
|
||||
visitor_name = "Visitor #%d (%s)" % (visitor.id, country.name) if country else f"Visitor #{visitor.id}"
|
||||
members_to_add = [Command.link(operator.partner_id.id)]
|
||||
if visitor.partner_id:
|
||||
members_to_add.append(Command.link(visitor.partner_id.id))
|
||||
@@ -116,6 +116,6 @@ class WebsiteVisitor(models.Model):
|
||||
discuss_channel = request.env["discuss.channel"].sudo().search([("uuid", "=", discuss_channel_uuid)])
|
||||
discuss_channel.write({
|
||||
'livechat_visitor_id': visitor_sudo.id,
|
||||
'anonymous_name': visitor_sudo.display_name
|
||||
'anonymous_name': "Visitor #%d (%s)" % (visitor_sudo.id, visitor_sudo.country_id.name) if visitor_sudo.country_id else f"Visitor #{visitor_sudo.id}"
|
||||
})
|
||||
return visitor_id, upsert
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { DEFAULT_AVATAR } from "@mail/core/common/persona_service";
|
||||
import { ThreadService } from "@mail/core/common/thread_service";
|
||||
import { assignDefined } from "@mail/utils/common/misc";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(ThreadService.prototype, {
|
||||
@@ -13,6 +14,7 @@ patch(ThreadService.prototype, {
|
||||
type: "visitor",
|
||||
});
|
||||
}
|
||||
assignDefined(thread, data, ["requested_by_operator"]);
|
||||
},
|
||||
/**
|
||||
* @param {import('@mail/core/common/persona_model').Persona} persona
|
||||
|
||||
@@ -12,9 +12,6 @@ patch(LivechatService.prototype, {
|
||||
},
|
||||
|
||||
get displayWelcomeMessage() {
|
||||
return (
|
||||
(this.thread.messages.length === 0 || this.thread?.messages[0]?.isSelfAuthored) &&
|
||||
super.displayWelcomeMessage
|
||||
);
|
||||
return !this.thread.requested_by_operator;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { ThreadService } from "@mail/core/common/thread_service";
|
||||
import { assignDefined } from "@mail/utils/common/misc";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(ThreadService.prototype, {
|
||||
update(thread, data) {
|
||||
super.update(thread, data);
|
||||
assignDefined(thread, data, ["requested_by_operator"]);
|
||||
},
|
||||
});
|
||||
@@ -54,6 +54,7 @@ class TestLivechatRequestHttpCase(tests.HttpCase, TestLivechatCommon):
|
||||
self.assertEqual(len(channel), 1)
|
||||
self.assertEqual(channel.livechat_operator_id, self.operator.partner_id, "Michel Operator should be the operator of this channel.")
|
||||
self.assertEqual(len(channel.message_ids), 0)
|
||||
self.assertEqual(channel.anonymous_name, f"Visitor #{self.visitor.id} ({self.visitor.country_id.name})")
|
||||
|
||||
# Operator Sends message
|
||||
self._send_message(channel, self.operator.email, "Hello Again !", author_id=self.operator.partner_id.id)
|
||||
|
||||
Reference in New Issue
Block a user