Skip to content

Commit 79cce73

Browse files
pmah-odooalexkuhn
authored andcommitted
[FIX] mail, im_livechat: avoid creating chat bubble when discuss is open
Before this commit, receiving a message while the Discuss app was open still created a chat bubble in the background. These would appear after leaving the Discuss app. This commit avoids inserting chat bubbles when Discuss is active, except for livechat messages. Messages still trigger notifications without creating bubbles task-4752392 closes odoo#219796 X-original-commit: 888e2ca Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
1 parent 49b6bb1 commit 79cce73

4 files changed

Lines changed: 106 additions & 26 deletions

File tree

addons/im_livechat/static/src/core/public_web/thread_model_patch.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ patch(Thread.prototype, {
6262
return super.avatarUrl;
6363
},
6464

65+
get inChathubOnNewMessage() {
66+
return this.channel_type === "livechat" || super.inChathubOnNewMessage;
67+
},
68+
6569
/**
6670
* @override
6771
* @param {boolean} pushState

addons/im_livechat/static/tests/chat_window_patch.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
click,
33
contains,
44
openDiscuss,
5+
openFormView,
56
setupChatHub,
67
start,
78
startServer,
@@ -138,3 +139,53 @@ test("do not ask confirmation if other operators are present", async () => {
138139
await click("[title*='Close Chat Window']");
139140
await contains(".o_notification", { text: "You left Visitor #12." });
140141
});
142+
143+
test.tags("desktop");
144+
test("Show livechats with new message in chat hub even when in discuss app)", async () => {
145+
// Chat hub show conversations with new message only when outside of discuss app by default.
146+
// Live chats are special in that agents are expected to see their ongoing conversations at all
147+
// time. Closing chat window ends the conversation. Hence the livechat always are shown on chat hub.
148+
const pyEnv = await startServer();
149+
const guestId = pyEnv["mail.guest"].create({ name: "Visitor 11" });
150+
const [livechatId, channelId] = pyEnv["discuss.channel"].create([
151+
{
152+
anonymous_name: "Visitor 11",
153+
channel_member_ids: [
154+
Command.create({ partner_id: serverState.partnerId }),
155+
Command.create({ guest_id: guestId }),
156+
],
157+
channel_type: "livechat",
158+
livechat_operator_id: serverState.partnerId,
159+
},
160+
{
161+
channel_member_ids: [Command.create({ partner_id: serverState.partnerId })],
162+
channel_type: "channel",
163+
name: "general",
164+
},
165+
]);
166+
pyEnv["mail.message"].create({
167+
author_id: serverState.partnerId,
168+
body: "<p>Test</p>",
169+
message_type: "comment",
170+
model: "discuss.channel",
171+
res_id: channelId,
172+
});
173+
await start();
174+
await openDiscuss(channelId);
175+
await contains(".o-mail-Message:contains('Test')");
176+
// simulate livechat visitor sending a message
177+
await withGuest(guestId, () =>
178+
rpc("/mail/message/post", {
179+
post_data: {
180+
body: "Hello, I need help!",
181+
message_type: "comment",
182+
subtype_xmlid: "mail.mt_comment",
183+
},
184+
thread_id: livechatId,
185+
thread_model: "discuss.channel",
186+
})
187+
);
188+
await contains(".o-mail-DiscussSidebar-item:contains('Visitor 11') .badge", { text: "1" });
189+
await openFormView("res.partner", serverState.partnerId);
190+
await contains(".o-mail-ChatWindow-header:contains('Visitor 11')");
191+
});

addons/mail/static/src/core/public_web/thread_model_patch.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ patch(Thread.prototype, {
2929
(channel_notifications === "mentions" &&
3030
message.recipients?.includes(this.store.self)))))
3131
) {
32-
if (this.model === "discuss.channel") {
32+
if (this.model === "discuss.channel" && this.inChathubOnNewMessage) {
3333
await this.store.chatHub.initPromise;
3434
let chatWindow = this.store.ChatWindow.get({ thread: this });
3535
if (!chatWindow) {
3636
chatWindow = this.store.ChatWindow.insert({ thread: this });
3737
if (
3838
this.autoOpenChatWindowOnNewMessage &&
39-
!this.store.discuss.isActive &&
4039
this.store.chatHub.opened.length < this.store.chatHub.maxOpened
4140
) {
4241
chatWindow.open();
@@ -48,6 +47,10 @@ patch(Thread.prototype, {
4847
this.store.env.services["mail.out_of_focus"].notify(message, this);
4948
}
5049
},
50+
/** Condition for whether the conversation should become present in chat hub on new message */
51+
get inChathubOnNewMessage() {
52+
return !this.store.discuss.isActive;
53+
},
5154
get autoOpenChatWindowOnNewMessage() {
5255
return false;
5356
},

addons/mail/static/tests/messaging/messaging.test.js

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
click,
23
contains,
34
defineMailModels,
45
insertText,
@@ -58,42 +59,63 @@ test("Receiving a new message out of discuss app should open a chat bubble", asy
5859
await contains(".o-mail-ChatBubble[name='Dumbledore']");
5960
});
6061

61-
test("Receiving a new message in discuss app should open a chat bubble after leaving discuss app", async () => {
62+
test("Show conversations with new message in chat hub (outside of discuss app)", async () => {
6263
const pyEnv = await startServer();
6364
const partnerId = pyEnv["res.partner"].create({ name: "Dumbledore" });
6465
const userId = pyEnv["res.users"].create({ partner_id: partnerId });
65-
const channelId = pyEnv["discuss.channel"].create({
66-
channel_member_ids: [
67-
Command.create({ partner_id: serverState.partnerId }),
68-
Command.create({ partner_id: partnerId }),
69-
],
70-
channel_type: "chat",
71-
});
72-
onRpcBefore("/mail/data", (args) => {
73-
if (args.fetch_params.includes("init_messaging")) {
74-
asyncStep(`/mail/data - ${JSON.stringify(args)}`);
75-
}
76-
});
77-
await start();
78-
await waitForSteps([
79-
`/mail/data - ${JSON.stringify({
80-
fetch_params: ["failures", "systray_get_activities", "init_messaging"],
81-
context: { lang: "en", tz: "taht", uid: serverState.userId, allowed_company_ids: [1] },
82-
})}`,
66+
const [chatId, groupChatId] = pyEnv["discuss.channel"].create([
67+
{
68+
channel_member_ids: [
69+
Command.create({ partner_id: serverState.partnerId }),
70+
Command.create({ partner_id: partnerId }),
71+
],
72+
channel_type: "chat",
73+
},
74+
{
75+
channel_member_ids: [
76+
Command.create({ partner_id: serverState.partnerId }),
77+
Command.create({ partner_id: partnerId }),
78+
],
79+
channel_type: "group",
80+
name: "GroupChat",
81+
},
8382
]);
84-
// send after init_messaging because bus subscription is done after init_messaging
83+
await start();
84+
// simulate receiving new message (chat, outside discuss app)
85+
await withUser(userId, () =>
86+
rpc("/mail/message/post", {
87+
post_data: { body: "Chat Message 1", message_type: "comment" },
88+
thread_id: chatId,
89+
thread_model: "discuss.channel",
90+
})
91+
);
92+
await click(".o-mail-ChatBubble[name='Dumbledore']");
93+
await contains(".o-mail-ChatWindow-header:contains('Dumbledore')");
94+
await click(".o-mail-ChatWindow [title*='Close Chat Window']");
95+
// simulate receiving new message (group chat, outside discuss app)
96+
await withUser(userId, () =>
97+
rpc("/mail/message/post", {
98+
post_data: { body: "GroupChat Message", message_type: "comment" },
99+
thread_id: groupChatId,
100+
thread_model: "discuss.channel",
101+
})
102+
);
103+
await contains(".o-mail-ChatBubble[name='GroupChat']");
85104
await openDiscuss();
86-
// simulate receiving new message
105+
// simulate receiving new message (chat, inside discuss app)
87106
await withUser(userId, () =>
88107
rpc("/mail/message/post", {
89108
post_data: { body: "Tricky", message_type: "comment" },
90-
thread_id: channelId,
109+
thread_id: chatId,
91110
thread_model: "discuss.channel",
92111
})
93112
);
94-
// leaving discuss.
113+
await contains(".o-mail-DiscussSidebar-item:contains('Dumbledore') .badge", { text: "1" });
114+
// check no new chat window/bubble while in discuss app
95115
await openFormView("res.partner", partnerId);
96-
await contains(".o-mail-ChatBubble[name='Dumbledore']");
116+
await contains(".o-mail-ChatBubble[name='GroupChat']");
117+
await contains(".o-mail-ChatBubble[name='Dumbledore']", { count: 0 });
118+
await contains(".o-mail-ChatWindow-header:contains('Dumbledore')", { count: 0 });
97119
});
98120

99121
test("Posting a message in discuss app should not open a chat window after leaving discuss app", async () => {

0 commit comments

Comments
 (0)