[REF] mail: move mail.link.preview/delete to new service

Part of task-3265211

Part-of: odoo/odoo#129583
This commit is contained in:
Sébastien Theys
2023-07-27 20:32:32 +02:00
parent b76db01aec
commit bc2aacd7b6
2 changed files with 11 additions and 12 deletions
@@ -1,6 +1,7 @@
/* @odoo-module */
import { LinkPreview } from "@mail/core/common/link_preview_model";
import { removeFromArrayWithPredicate } from "@mail/utils/common/arrays";
import { markup, reactive } from "@odoo/owl";
@@ -27,6 +28,16 @@ export class MailCoreCommon {
setup() {
this.messagingService.isReady.then(() => {
this.busService.subscribe("mail.link.preview/delete", (payload) => {
const { id, message_id } = payload;
const message = this.store.messages[message_id];
if (message) {
removeFromArrayWithPredicate(
message.linkPreviews,
(linkPreview) => linkPreview.id === id
);
}
});
this.busService.subscribe("mail.record/insert", (payload) => {
if (payload.Thread) {
this.threadService.insert(payload.Thread);
@@ -129,18 +129,6 @@ export class Messaging {
handleNotification(notifications) {
for (const notif of notifications) {
switch (notif.type) {
case "mail.link.preview/delete":
{
const { id, message_id } = notif.payload;
const message = this.store.messages[message_id];
if (message) {
removeFromArrayWithPredicate(
message.linkPreviews,
(linkPreview) => linkPreview.id === id
);
}
}
break;
case "mail.message/inbox": {
const data = Object.assign(notif.payload, { body: markup(notif.payload.body) });
const message = this.messageService.insert(data);