[FIX] mail: new messages not showing for unknown channel types

Before this PR, messages received on channels with unknown channel
types weren't displayed on discuss. This was due to the fact that
the sidebar computed its items based on the channel type.

Steps to reproduce this issue:
- Open one browser as mitchell admin (on the Discuss app).
- Open one browser as marc demo (on the Discuss app).
- Send a message from admin to demo.
- Unpin the channel on the admin browser.
- Refresh admin browser.
- Send a message from demo to admin.
- The message is not received on the admin browser.

This PR fixes the issue by fetching channel data if the channel type
is missing when receiving a new message.

closes odoo/odoo#113377

X-original-commit: 3398aa8b10a1d9ad75552871e532f57ffcdd4a7f
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Stockbauer Matthieu (tsm) <tsm@odoo.com>
This commit is contained in:
tsm-odoo
2023-02-22 15:39:04 +01:00
parent d4a4a3c1de
commit 8fad8e6a26
4 changed files with 66 additions and 10 deletions
@@ -287,7 +287,7 @@ Model({
// particular the case with the `uuid` field that is assumed
// "required" by the rest of the code and is necessary for some
// features such as chat windows.
if (!channel) {
if (!channel || !channel.channel_type) {
const res = await this.messaging.models["Thread"].performRpcChannelInfo({
ids: [channelId],
});
@@ -232,14 +232,6 @@ patch(MockServer.prototype, "mail/models/mail_thread", {
// members
const channels = this.getRecords("mail.channel", [["id", "=", message.res_id]]);
for (const channel of channels) {
notifications.push([
channel,
"mail.channel/new_message",
{
id: channel.id,
message: messageFormat,
},
]);
// notify update of last_interest_dt
const now = datetime_to_str(new Date());
const members = this.getRecords("mail.channel.member", [
@@ -256,10 +248,19 @@ patch(MockServer.prototype, "mail/models/mail_thread", {
"mail.channel/last_interest_dt_changed",
{
id: channel.id,
isServerPinned: member.is_pinned,
last_interest_dt: member.last_interest_dt,
},
]);
}
notifications.push([
channel,
"mail.channel/new_message",
{
id: channel.id,
message: messageFormat,
},
]);
}
}
this.pyEnv["bus.bus"]._sendmany(notifications);
+10 -1
View File
@@ -105,7 +105,16 @@ function getAfterEvent({ messagingBus }) {
function getClick({ afterNextRender }) {
return async function click(selector) {
await afterNextRender(() => document.querySelector(selector).click());
await afterNextRender(() => {
if (typeof selector === "string") {
$(selector)[0].click();
} else if (selector instanceof HTMLElement) {
selector.click();
} else {
// jquery
selector[0].click();
}
});
};
}
@@ -4011,3 +4011,49 @@ QUnit.module("mail", {}, function () {
);
});
});
QUnit.test("Message shows up even if channel data is incomplete", async function (assert) {
const { click, env, openDiscuss, pyEnv } = await start();
await openDiscuss();
const correspondentUserId = pyEnv["res.users"].create({ name: "Albert" });
const correspondentPartnerId = pyEnv["res.partner"].create({
name: "Albert",
user_ids: [correspondentUserId],
});
const channelId = pyEnv["mail.channel"].create({
channel_member_ids: [
[
0,
0,
{
is_pinned: true,
partner_id: pyEnv.currentPartnerId,
},
],
[0, 0, { partner_id: correspondentPartnerId }],
],
channel_type: "chat",
});
await env.services.rpc("/mail/channel/notify_typing", {
context: {
mockedPartnerId: correspondentPartnerId,
},
is_typing: true,
channel_id: channelId,
});
const [channel] = pyEnv["mail.channel"].searchRead([["id", "=", channelId]]);
await afterNextRender(
async () =>
await env.services.rpc("/mail/chat_post", {
context: {
mockedUserId: correspondentUserId,
},
message_content: "hello world",
uuid: channel.uuid,
})
);
await click(
".o_DiscussSidebarView_categoryChat .o_DiscussSidebarCategoryItem:contains(Albert)"
);
assert.containsOnce(document.body, ".o_MessageView:contains(hello world)");
});