[IMP] im_livechat: use guest avatar for live chat visitors
task-3471571 closes odoo/odoo#137806 Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit is contained in:
@@ -31,3 +31,25 @@ class LivechatBinaryController(BinaryController):
|
||||
def livechat_fetch_image(self, guest_token, channel_id, attachment_id, width=0, height=0, **kwargs):
|
||||
force_guest_env(guest_token)
|
||||
return self.fetch_image(channel_id, attachment_id, width, height, **kwargs)
|
||||
|
||||
@route(
|
||||
"/im_livechat/cors/channel/<int:channel_id>/partner/<int:partner_id>/avatar_128",
|
||||
methods=["GET"],
|
||||
type="http",
|
||||
auth="public",
|
||||
cors="*",
|
||||
)
|
||||
def livechat_channel_partner_avatar_128(self, guest_token, channel_id, partner_id, **kwargs):
|
||||
force_guest_env(guest_token)
|
||||
return self.discuss_channel_partner_avatar_128(channel_id, partner_id, **kwargs)
|
||||
|
||||
@route(
|
||||
"/im_livechat/cors/channel/<int:channel_id>/guest/<int:guest_id>/avatar_128",
|
||||
methods=["GET"],
|
||||
type="http",
|
||||
auth="public",
|
||||
cors="*",
|
||||
)
|
||||
def livechat_channel_guest_avatar_128(self, guest_token, channel_id, guest_id, **kwargs):
|
||||
force_guest_env(guest_token)
|
||||
return self.discuss_channel_guest_avatar_128(channel_id, guest_id, **kwargs)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { DEFAULT_AVATAR } from "@mail/core/common/persona_service";
|
||||
import { Record } from "@mail/core/common/record";
|
||||
import { Thread } from "@mail/core/common/thread_model";
|
||||
import { assignDefined } from "@mail/utils/common/misc";
|
||||
@@ -82,9 +81,7 @@ patch(Thread.prototype, {
|
||||
if (this.type !== "livechat") {
|
||||
return super.imgUrl;
|
||||
}
|
||||
return this.correspondent && this.correspondent.type !== "guest"
|
||||
? `/web/image/res.partner/${this.correspondent.id}/avatar_128`
|
||||
: DEFAULT_AVATAR;
|
||||
return this._store.env.services["mail.thread"].avatarUrl(this.correspondent, this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { DEFAULT_AVATAR } from "@mail/core/common/persona_service";
|
||||
import { ThreadService } from "@mail/core/common/thread_service";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
@@ -67,15 +66,4 @@ patch(ThreadService.prototype, {
|
||||
this.chatWindowService.focus(chatWindow);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {import("models").Persona} persona
|
||||
* @param {import("models").Thread} thread
|
||||
*/
|
||||
avatarUrl(author, thread) {
|
||||
if (thread?.type === "livechat" && author?.type === "guest") {
|
||||
return DEFAULT_AVATAR;
|
||||
}
|
||||
return super.avatarUrl(author, thread);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,5 +2,6 @@ declare module "models" {
|
||||
export interface Thread {
|
||||
chatbotTypingMessage: Message,
|
||||
livechatWelcomeMessage: Message,
|
||||
operator: Persona,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ patch(Thread.prototype, {
|
||||
super.setup();
|
||||
this.chatbotTypingMessage = Record.one("Message");
|
||||
this.livechatWelcomeMessage = Record.one("Message");
|
||||
this.operator = Record.one("Persona");
|
||||
},
|
||||
update(data) {
|
||||
super.update(...arguments);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { ThreadService, threadService } from "@mail/core/common/thread_service";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { session } from "@web/session";
|
||||
import { url } from "@web/core/utils/urls";
|
||||
|
||||
threadService.dependencies.push(
|
||||
"im_livechat.livechat",
|
||||
@@ -63,20 +63,10 @@ patch(ThreadService.prototype, {
|
||||
}
|
||||
},
|
||||
|
||||
avatarUrl(author, thread) {
|
||||
if (thread?.type !== "livechat") {
|
||||
return super.avatarUrl(...arguments);
|
||||
}
|
||||
const isFromOperator =
|
||||
author && author.id !== this.livechatService.options.current_partner_id;
|
||||
if (isFromOperator) {
|
||||
return `${session.origin}/im_livechat/operator/${
|
||||
author?.id ?? thread.operator.id
|
||||
}/avatar`;
|
||||
} else if (author) {
|
||||
return `${session.origin}/web/image/res.partner/${author.id}/avatar_128`;
|
||||
} else {
|
||||
return `${session.origin}/mail/static/src/img/smiley/avatar.jpg`;
|
||||
avatarUrl(persona, thread) {
|
||||
if (thread.type === "livechat" && persona.eq(thread.operator)) {
|
||||
return url(`/im_livechat/operator/${persona.id}/avatar`);
|
||||
}
|
||||
return super.avatarUrl(...arguments);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { ThreadService } from "@mail/core/common/thread_service";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { url } from "@web/core/utils/urls";
|
||||
|
||||
patch(ThreadService.prototype, {
|
||||
avatarUrl(persona, thread) {
|
||||
if (thread?.model === "discuss.channel" && persona.notEq(thread.operator)) {
|
||||
const route =
|
||||
persona.type === "partner"
|
||||
? `/im_livechat/cors/channel/${thread.id}/partner/${persona.id}/avatar_128`
|
||||
: `/im_livechat/cors/channel/${thread.id}/guest/${persona.id}/avatar_128`;
|
||||
return url(route, {
|
||||
guest_token: this.env.services["im_livechat.livechat"].guestToken,
|
||||
});
|
||||
}
|
||||
return super.avatarUrl(...arguments);
|
||||
},
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import { startServer } from "@bus/../tests/helpers/mock_python_environment";
|
||||
import { Command } from "@mail/../tests/helpers/command";
|
||||
import { start } from "@mail/../tests/helpers/test_utils";
|
||||
|
||||
import { url } from "@web/core/utils/urls";
|
||||
import { nextTick } from "@web/../tests/helpers/utils";
|
||||
import { click, contains } from "@web/../tests/utils";
|
||||
|
||||
@@ -220,10 +221,10 @@ QUnit.test("Close from the bus", async () => {
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("Smiley face avatar for an anonymous livechat item", async () => {
|
||||
QUnit.test("Smiley face avatar for livechat item linked to a guest", async () => {
|
||||
const pyEnv = await startServer();
|
||||
const guestId = pyEnv["mail.guest"].create({ name: "Visitor 11" });
|
||||
pyEnv["discuss.channel"].create({
|
||||
const channelId = pyEnv["discuss.channel"].create({
|
||||
anonymous_name: "Visitor 11",
|
||||
channel_member_ids: [
|
||||
[0, 0, { partner_id: pyEnv.currentPartnerId }],
|
||||
@@ -235,7 +236,9 @@ QUnit.test("Smiley face avatar for an anonymous livechat item", async () => {
|
||||
const { openDiscuss } = await start();
|
||||
openDiscuss();
|
||||
await contains(
|
||||
".o-mail-DiscussSidebarCategory-livechat + .o-mail-DiscussSidebarChannel img[data-src='/mail/static/src/img/smiley/avatar.jpg']"
|
||||
`.o-mail-DiscussSidebarCategory-livechat + .o-mail-DiscussSidebarChannel img[data-src='${url(
|
||||
`/discuss/channel/${channelId}/guest/${guestId}/avatar_128`
|
||||
)}']`
|
||||
);
|
||||
});
|
||||
|
||||
@@ -253,7 +256,9 @@ QUnit.test("Partner profile picture for livechat item linked to a partner", asyn
|
||||
const { openDiscuss } = await start();
|
||||
openDiscuss(channelId);
|
||||
await contains(
|
||||
`.o-mail-DiscussSidebarCategory-livechat + .o-mail-DiscussSidebarChannel img[data-src='/web/image/res.partner/${partnerId}/avatar_128']`
|
||||
`.o-mail-DiscussSidebarCategory-livechat + .o-mail-DiscussSidebarChannel img[data-src='${url(
|
||||
`/discuss/channel/${channelId}/partner/${partnerId}/avatar_128`
|
||||
)}']`
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<t t-set="visitor" t-value="props.thread.visitor"/>
|
||||
<div t-if="visitor and !env.inChatWindow" class="o-website_livechat-VisitorBanner py-4 px-2 d-flex border-bottom">
|
||||
<div class="o-website_livechat-VisitorBanner-sidebar me-2 d-flex justify-content-center">
|
||||
<img class="rounded o-website_livechat-VisitorBanner-avatar" t-att-src="threadService.avatarUrl(visitor, props.thread)" alt="Avatar"/>
|
||||
<img class="rounded o-website_livechat-VisitorBanner-avatar" t-att-src="threadService.avatarUrl(props.thread.correspondent, props.thread)" alt="Avatar"/>
|
||||
</div>
|
||||
<div>
|
||||
<div class="d-flex align-items-baseline">
|
||||
|
||||
@@ -5,6 +5,8 @@ import { startServer } from "@bus/../tests/helpers/mock_python_environment";
|
||||
import { Command } from "@mail/../tests/helpers/command";
|
||||
import { start } from "@mail/../tests/helpers/test_utils";
|
||||
|
||||
import { url } from "@web/core/utils/urls";
|
||||
|
||||
QUnit.module("thread (patch)");
|
||||
|
||||
QUnit.test("Rendering of visitor banner", async (assert) => {
|
||||
@@ -36,7 +38,9 @@ QUnit.test("Rendering of visitor banner", async (assert) => {
|
||||
assert.containsOnce($, "img.o-website_livechat-VisitorBanner-avatar");
|
||||
assert.containsOnce(
|
||||
$,
|
||||
"img.o-website_livechat-VisitorBanner-avatar[data-src='/mail/static/src/img/smiley/avatar.jpg']"
|
||||
`img.o-website_livechat-VisitorBanner-avatar[data-src='${url(
|
||||
`/discuss/channel/${channelId}/guest/${guestId}/avatar_128`
|
||||
)}']`
|
||||
);
|
||||
assert.containsOnce($, ".o-website_livechat-VisitorBanner .o-mail-ImStatus");
|
||||
assert.containsOnce($, ".o_country_flag[data-src='/base/static/img/country_flags/be.png']");
|
||||
|
||||
Reference in New Issue
Block a user