[FIX] mail, im_livechat: do not start bus for transient threads
Since [1], the websocket worker is started when a transient thread is added to the mail store. This occurs because this PR introduced a call to the `addChannel` method of the bus service when the current user was not member of the thread. Since transient threads are not yet created, they have a partial state that does not necessarily include channel members hence the impression that the current user is not member of the channel. This PR prevent starting the bus service for transient threads. [1]: https://github.com/odoo/odoo/pull/146800 closes odoo/odoo#153000 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
@@ -35,7 +35,7 @@ export const ODOO_VERSION_KEY = `${location.origin.replace(
|
||||
)}_im_livechat.odoo_version`;
|
||||
|
||||
export class LivechatService {
|
||||
TEMPORARY_ID = "livechat_temporary_thread";
|
||||
static TEMPORARY_ID = "livechat_temporary_thread";
|
||||
SESSION_COOKIE = "im_livechat_session";
|
||||
OPERATOR_COOKIE = "im_livechat_previous_operator_pid";
|
||||
GUEST_TOKEN_STORAGE_KEY = "im_livechat_guest_token";
|
||||
@@ -160,7 +160,7 @@ export class LivechatService {
|
||||
this.persistThreadPromise = null;
|
||||
}
|
||||
const chatWindow = this.store.discuss.chatWindows.find(
|
||||
(c) => c.thread.id === this.TEMPORARY_ID
|
||||
(c) => c.thread.id === LivechatService.TEMPORARY_ID
|
||||
);
|
||||
if (chatWindow) {
|
||||
chatWindow.thread?.delete();
|
||||
@@ -213,7 +213,7 @@ export class LivechatService {
|
||||
this.updateSession(threadData);
|
||||
const thread = this.store.Thread.insert({
|
||||
...threadData,
|
||||
id: threadData.id ?? this.TEMPORARY_ID,
|
||||
id: threadData.id ?? LivechatService.TEMPORARY_ID,
|
||||
isLoaded: !threadData.id || isNewlyCreated,
|
||||
model: "discuss.channel",
|
||||
type: "livechat",
|
||||
@@ -264,7 +264,8 @@ export class LivechatService {
|
||||
get thread() {
|
||||
return Object.values(this.store.Thread.records).find(
|
||||
({ id, type }) =>
|
||||
type === "livechat" && id === (this.sessionCookie?.id ?? this.TEMPORARY_ID)
|
||||
type === "livechat" &&
|
||||
id === (this.sessionCookie?.id ?? LivechatService.TEMPORARY_ID)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { SESSION_STATE } from "@im_livechat/embed/common/livechat_service";
|
||||
import { LivechatService, SESSION_STATE } from "@im_livechat/embed/common/livechat_service";
|
||||
|
||||
import { Record } from "@mail/core/common/record";
|
||||
import { Thread } from "@mail/core/common/thread_model";
|
||||
@@ -78,4 +78,8 @@ patch(Thread.prototype, {
|
||||
}
|
||||
return url(`/im_livechat/operator/${this.operator.id}/avatar`);
|
||||
},
|
||||
|
||||
get isTransient() {
|
||||
return super.isTransient || this.id === LivechatService.TEMPORARY_ID;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -207,7 +207,7 @@ export class Store extends BaseStore {
|
||||
const ids = Object.keys(this.Thread.records).sort(); // Ensure channels processed in same order.
|
||||
for (const id of ids) {
|
||||
const thread = this.Thread.records[id];
|
||||
if (thread.model === "discuss.channel") {
|
||||
if (thread.model === "discuss.channel" && !thread.isTransient) {
|
||||
channelIds.push(id);
|
||||
if (!thread.hasSelfAsMember) {
|
||||
this.env.services["bus_service"].addChannel(`discuss.channel_${thread.id}`);
|
||||
|
||||
@@ -5,13 +5,40 @@ import { registry } from "@web/core/registry";
|
||||
registry.category("web_tour.tours").add("website_livechat.lazy_frontend_bus", {
|
||||
test: true,
|
||||
url: "/",
|
||||
shadow_dom: ".o-livechat-root",
|
||||
steps: () => [
|
||||
{
|
||||
trigger: "body",
|
||||
trigger: ".o-livechat-LivechatButton",
|
||||
async run() {
|
||||
await odoo.__WOWL_DEBUG__.root.env.services["mail.messaging"].isReady;
|
||||
if (odoo.__WOWL_DEBUG__.root.env.services.bus_service.isActive) {
|
||||
throw new Error("Bus service should not be started eagerly");
|
||||
throw new Error("Bus service should not start when loading the page");
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
trigger: ".o-livechat-LivechatButton",
|
||||
},
|
||||
{
|
||||
trigger: ".o-mail-Composer-input",
|
||||
run: "text Hello, I need help!",
|
||||
},
|
||||
{
|
||||
trigger: ".o-mail-Composer-input",
|
||||
run() {
|
||||
if (odoo.__WOWL_DEBUG__.root.env.services.bus_service.isActive) {
|
||||
throw new Error("Bus service should not start for temporary live chat");
|
||||
}
|
||||
this.$anchor[0].dispatchEvent(
|
||||
new KeyboardEvent("keydown", { key: "Enter", which: 13, bubbles: true })
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
trigger: ".o-mail-Message:contains(Hello, I need help!)",
|
||||
run() {
|
||||
if (!odoo.__WOWL_DEBUG__.root.env.services.bus_service.isActive) {
|
||||
throw new Error("Bus service should start after first live chat message");
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user