[FIX] mail: no crash on receiving link preview of non-known message

This notification makes sense when we know this message. If we don't
know it yet, then we should just ignore and receive data of link
preview when fetching the message.

closes odoo/odoo#118647

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2023-04-14 19:45:52 +02:00
parent 544ead2b49
commit 41e0543932
3 changed files with 27 additions and 3 deletions
@@ -603,7 +603,7 @@ export class Messaging {
const { LinkPreview: linkPreviews } = notif.payload;
if (linkPreviews) {
for (const linkPreview of linkPreviews) {
this.store.messages[linkPreview.message.id].linkPreviews.push(
this.store.messages[linkPreview.message.id]?.linkPreviews.push(
new LinkPreview(linkPreview)
);
}
@@ -283,7 +283,9 @@ patch(MockServer.prototype, "mail/controllers/discuss", {
if (message.model === "mail.channel") {
target = this.pyEnv["mail.channel"].search([["id", "=", message.res_id]]);
}
this.pyEnv["bus.bus"]._sendmany([[target, "mail.link.preview/insert", linkPreviews]]);
this.pyEnv["bus.bus"]._sendmany([
[target, "mail.record/insert", { LinkPreview: linkPreviews }],
]);
}
},
/**
@@ -1,6 +1,6 @@
/** @odoo-module **/
import { click, start, startServer } from "@mail/../tests/helpers/test_utils";
import { click, nextAnimationFrame, start, startServer } from "@mail/../tests/helpers/test_utils";
QUnit.module("link preview");
@@ -240,3 +240,25 @@ QUnit.test("Remove link preview image", async (assert) => {
await click(".modal-footer button:contains(Ok)");
assert.containsNone($, ".o-mail-LinkPreviewImage");
});
QUnit.test("No crash on receiving link preview of non-known message", async (assert) => {
const pyEnv = await startServer();
const linkPreviewId = pyEnv["mail.link.preview"].create({
image_mimetype: "image/jpg",
source_url:
"https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Siberischer_tiger_de_edit02.jpg/290px-Siberischer_tiger_de_edit02.jpg",
});
const channelId = pyEnv["mail.channel"].create({ name: "wololo" });
const messageId = pyEnv["mail.message"].create({
body: "https://make-link-preview.com",
link_preview_ids: [linkPreviewId],
message_type: "comment",
model: "mail.channel",
res_id: channelId,
});
const { env, openDiscuss } = await start();
await openDiscuss();
env.services.rpc("/mail/link_preview", { message_id: messageId });
await nextAnimationFrame();
assert.ok(true);
});