[FIX] im_livechat: keep same livechat name after inviting members
Before this commit, inviting a channel member to a livechat channel would change its name. This is not what we want as the thread name should always be the one of the visitor (e.g. "Visitor 20", task-3332872). Steps to reproduce: - Open two tabs, one with admin log, one on the support page - Click on the livechat button and send a message from the support page - Invite a member with the admin tab - The name of the thread changed. closes odoo/odoo#128238 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
@@ -34,6 +34,22 @@ patch(Thread.prototype, "im_livechat", {
|
||||
return this._super().filter((correspondent) => !correspondent.is_bot);
|
||||
},
|
||||
|
||||
get correspondent() {
|
||||
let correspondent = this._super();
|
||||
if (this.type === "livechat" && !correspondent) {
|
||||
// For livechat threads, the correspondent is the first
|
||||
// channel member that is not the operator.
|
||||
const orderedChannelMembers = [...this.channelMembers].sort((a, b) => a.id - b.id);
|
||||
const isFirstMemberOperator =
|
||||
orderedChannelMembers[0]?.persona.type === "partner" &&
|
||||
orderedChannelMembers[0]?.persona.id === this.operator.id;
|
||||
correspondent = isFirstMemberOperator
|
||||
? orderedChannelMembers[1]?.persona
|
||||
: orderedChannelMembers[0]?.persona;
|
||||
}
|
||||
return correspondent;
|
||||
},
|
||||
|
||||
get displayName() {
|
||||
if (this.type !== "livechat" || !this.correspondent) {
|
||||
return this._super();
|
||||
|
||||
@@ -14,6 +14,13 @@ patch(ThreadService.prototype, "im_livechat", {
|
||||
if (data?.channel) {
|
||||
assignDefined(thread, data.channel, ["anonymous_name"]);
|
||||
}
|
||||
if (data?.operator_pid) {
|
||||
thread.operator = this.personaService.insert({
|
||||
type: "partner",
|
||||
id: data.operator_pid[0],
|
||||
displayName: data.operator_pid[1],
|
||||
});
|
||||
}
|
||||
if (isUnknown) {
|
||||
this.store.discuss.livechat.threads.push(thread.localId);
|
||||
this.sortChannels();
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { startServer } from "@bus/../tests/helpers/mock_python_environment";
|
||||
|
||||
import { Command } from "@mail/../tests/helpers/command";
|
||||
import { click, start } from "@mail/../tests/helpers/test_utils";
|
||||
|
||||
QUnit.module("Thread model");
|
||||
|
||||
QUnit.test("Thread name unchanged when inviting new users", async (assert) => {
|
||||
const pyEnv = await startServer();
|
||||
const userId = pyEnv["res.users"].create({ name: "James" });
|
||||
pyEnv["res.partner"].create({
|
||||
name: "James",
|
||||
user_ids: [userId],
|
||||
});
|
||||
const channelId = pyEnv["discuss.channel"].create({
|
||||
anonymous_name: "Visitor #20",
|
||||
channel_member_ids: [
|
||||
Command.create({ partner_id: pyEnv.currentPartnerId }),
|
||||
Command.create({ partner_id: pyEnv.publicPartnerId }),
|
||||
],
|
||||
channel_type: "livechat",
|
||||
livechat_operator_id: pyEnv.currentPartnerId,
|
||||
});
|
||||
const { openDiscuss } = await start();
|
||||
await openDiscuss(channelId);
|
||||
assert.containsOnce($, ".o-mail-Discuss-threadName[title='Visitor #20']");
|
||||
await click("button[title='Add Users']");
|
||||
await click(".o-discuss-ChannelInvitation-selectable:contains(James) input");
|
||||
await click("button:contains(Invite)");
|
||||
await click("button[title='Show Member List']");
|
||||
assert.containsOnce($, ".o-discuss-ChannelMember:contains(James)");
|
||||
assert.containsOnce($, ".o-mail-Discuss-threadName[title='Visitor #20']");
|
||||
});
|
||||
Reference in New Issue
Block a user