[REF] mail: move mail.record/insert to new services
Part of task-3265211 Part-of: odoo/odoo#129583
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { LinkPreview } from "@mail/core/common/link_preview_model";
|
||||
|
||||
import { markup, reactive } from "@odoo/owl";
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
export class MailCoreCommon {
|
||||
constructor(env, services) {
|
||||
Object.assign(this, {
|
||||
busService: services.bus_service,
|
||||
});
|
||||
/** @type {import("@mail/core/common/message_service").MessageService} */
|
||||
this.messageService = services["mail.message"];
|
||||
/** @type {import("@mail/core/common/messaging_service").Messaging} */
|
||||
this.messagingService = services["mail.messaging"];
|
||||
/** @type {import("@mail/core/common/persona_service").PersonaService} */
|
||||
this.personaService = services["mail.persona"];
|
||||
/** @type {import("@mail/core/common/store_service").Store} */
|
||||
this.store = services["mail.store"];
|
||||
/** @type {import("@mail/core/common/thread_service").ThreadService} */
|
||||
this.threadService = services["mail.thread"];
|
||||
/** @type {import("@mail/core/common/user_settings_service").UserSettings} */
|
||||
this.userSettingsService = services["mail.user_settings"];
|
||||
}
|
||||
|
||||
setup() {
|
||||
this.messagingService.isReady.then(() => {
|
||||
this.busService.subscribe("mail.record/insert", (payload) => {
|
||||
if (payload.Thread) {
|
||||
this.threadService.insert(payload.Thread);
|
||||
}
|
||||
if (payload.Partner) {
|
||||
const partners = Array.isArray(payload.Partner)
|
||||
? payload.Partner
|
||||
: [payload.Partner];
|
||||
for (const partner of partners) {
|
||||
if (partner.im_status) {
|
||||
this.personaService.insert({ ...partner, type: "partner" });
|
||||
}
|
||||
}
|
||||
}
|
||||
if (payload.Guest) {
|
||||
const guests = Array.isArray(payload.Guest) ? payload.Guest : [payload.Guest];
|
||||
for (const guest of guests) {
|
||||
this.personaService.insert({ ...guest, type: "guest" });
|
||||
}
|
||||
}
|
||||
const { LinkPreview: linkPreviews } = payload;
|
||||
if (linkPreviews) {
|
||||
for (const linkPreview of linkPreviews) {
|
||||
this.store.messages[linkPreview.message.id]?.linkPreviews.push(
|
||||
new LinkPreview(linkPreview)
|
||||
);
|
||||
}
|
||||
}
|
||||
const { Message: messageData } = payload;
|
||||
if (messageData) {
|
||||
const isStarred = this.store.messages[messageData.id]?.isStarred;
|
||||
const message = this.messageService.insert({
|
||||
...messageData,
|
||||
body: messageData.body ? markup(messageData.body) : messageData.body,
|
||||
});
|
||||
if (isStarred && message.isEmpty) {
|
||||
this.messageService.updateStarred(message, false);
|
||||
}
|
||||
}
|
||||
const { "res.users.settings": settings } = payload;
|
||||
if (settings) {
|
||||
this.userSettingsService.updateFromCommands(settings);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const mailCoreCommon = {
|
||||
dependencies: [
|
||||
"bus_service",
|
||||
"mail.message",
|
||||
"mail.messaging",
|
||||
"mail.persona",
|
||||
"mail.store",
|
||||
"mail.thread",
|
||||
"mail.user_settings",
|
||||
],
|
||||
start(env, services) {
|
||||
const mailCoreCommon = reactive(new MailCoreCommon(env, services));
|
||||
mailCoreCommon.setup();
|
||||
return mailCoreCommon;
|
||||
},
|
||||
};
|
||||
|
||||
registry.category("services").add("mail.core.common", mailCoreCommon);
|
||||
@@ -1,7 +1,6 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { CannedResponse } from "@mail/core/common/canned_response_model";
|
||||
import { LinkPreview } from "@mail/core/common/link_preview_model";
|
||||
import { removeFromArray, removeFromArrayWithPredicate } from "@mail/utils/common/arrays";
|
||||
import { cleanTerm } from "@mail/utils/common/format";
|
||||
|
||||
@@ -130,9 +129,6 @@ export class Messaging {
|
||||
handleNotification(notifications) {
|
||||
for (const notif of notifications) {
|
||||
switch (notif.type) {
|
||||
case "mail.record/insert":
|
||||
this._handleNotificationRecordInsert(notif);
|
||||
break;
|
||||
case "mail.link.preview/delete":
|
||||
{
|
||||
const { id, message_id } = notif.payload;
|
||||
@@ -278,70 +274,6 @@ export class Messaging {
|
||||
}
|
||||
}
|
||||
|
||||
_handleNotificationRecordInsert(notif) {
|
||||
if (notif.payload.Thread) {
|
||||
this.threadService.insert(notif.payload.Thread);
|
||||
}
|
||||
|
||||
if (notif.payload.Channel) {
|
||||
this.threadService.insert({
|
||||
id: notif.payload.Channel.id,
|
||||
model: "discuss.channel",
|
||||
channel: notif.payload.Channel,
|
||||
});
|
||||
}
|
||||
if (notif.payload.Partner) {
|
||||
const partners = Array.isArray(notif.payload.Partner)
|
||||
? notif.payload.Partner
|
||||
: [notif.payload.Partner];
|
||||
for (const partner of partners) {
|
||||
if (partner.im_status) {
|
||||
this.personaService.insert({ ...partner, type: "partner" });
|
||||
}
|
||||
}
|
||||
}
|
||||
if (notif.payload.Guest) {
|
||||
const guests = Array.isArray(notif.payload.Guest)
|
||||
? notif.payload.Guest
|
||||
: [notif.payload.Guest];
|
||||
for (const guest of guests) {
|
||||
this.personaService.insert({ ...guest, type: "guest" });
|
||||
}
|
||||
}
|
||||
const { LinkPreview: linkPreviews } = notif.payload;
|
||||
if (linkPreviews) {
|
||||
for (const linkPreview of linkPreviews) {
|
||||
this.store.messages[linkPreview.message.id]?.linkPreviews.push(
|
||||
new LinkPreview(linkPreview)
|
||||
);
|
||||
}
|
||||
}
|
||||
const { Message: messageData } = notif.payload;
|
||||
if (messageData) {
|
||||
const isStarred = this.store.messages[messageData.id]?.isStarred;
|
||||
const message = this.messageService.insert({
|
||||
...messageData,
|
||||
body: messageData.body ? markup(messageData.body) : messageData.body,
|
||||
});
|
||||
if (isStarred && message.isEmpty) {
|
||||
this.messageService.updateStarred(message, false);
|
||||
}
|
||||
}
|
||||
const { "res.users.settings": settings } = notif.payload;
|
||||
if (settings) {
|
||||
this.userSettingsService.updateFromCommands(settings);
|
||||
this.store.discuss.chats.isOpen =
|
||||
settings.is_discuss_sidebar_category_chat_open ?? this.store.discuss.chats.isOpen;
|
||||
this.store.discuss.channels.isOpen =
|
||||
settings.is_discuss_sidebar_category_channel_open ??
|
||||
this.store.discuss.channels.isOpen;
|
||||
}
|
||||
const { "res.users.settings.volumes": volumeSettings } = notif.payload;
|
||||
if (volumeSettings) {
|
||||
this.userSettingsService.setVolumes(volumeSettings);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// actions that can be performed on the messaging system
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -1533,15 +1533,15 @@ export class Rtc {
|
||||
|
||||
export const rtcService = {
|
||||
dependencies: [
|
||||
"bus_service",
|
||||
"discuss.channel.member",
|
||||
"mail.persona",
|
||||
"mail.sound_effects",
|
||||
"mail.store",
|
||||
"mail.thread",
|
||||
"mail.user_settings",
|
||||
"notification",
|
||||
"rpc",
|
||||
"bus_service",
|
||||
"mail.sound_effects",
|
||||
"mail.user_settings",
|
||||
"mail.thread",
|
||||
"mail.persona",
|
||||
],
|
||||
start(env, services) {
|
||||
const rtc = new Rtc(env, services);
|
||||
@@ -1575,9 +1575,13 @@ export const rtcService = {
|
||||
const command = rtcSessions[0][0];
|
||||
rtc.updateRtcSessions(channel.id, sessionsData, command);
|
||||
});
|
||||
services["bus_service"].subscribe("mail.record/insert", ({ RtcSession }) => {
|
||||
if (RtcSession) {
|
||||
rtc.insertSession(RtcSession);
|
||||
services["bus_service"].subscribe("mail.record/insert", (payload) => {
|
||||
if (payload.RtcSession) {
|
||||
rtc.insertSession(payload.RtcSession);
|
||||
}
|
||||
const { "res.users.settings.volumes": volumeSettings } = payload;
|
||||
if (volumeSettings) {
|
||||
services["mail.user_settings"].setVolumes(volumeSettings);
|
||||
}
|
||||
});
|
||||
return rtc;
|
||||
|
||||
@@ -15,6 +15,7 @@ export class DiscussCoreCommon {
|
||||
Object.assign(this, {
|
||||
busService: services.bus_service,
|
||||
env,
|
||||
notificationService: services.notification,
|
||||
orm: services.orm,
|
||||
presence: services.presence,
|
||||
rpc: services.rpc,
|
||||
@@ -23,13 +24,12 @@ export class DiscussCoreCommon {
|
||||
this.messageService = services["mail.message"];
|
||||
/** @type {import("@mail/core/common/messaging_service").Messaging} */
|
||||
this.messagingService = services["mail.messaging"];
|
||||
this.notificationService = services.notification;
|
||||
/** @type {import("@mail/core/common/out_of_focus_service").OutOfFocusService} */
|
||||
this.outOfFocusService = services["mail.out_of_focus"];
|
||||
/** @type {import("@mail/core/common/thread_service").ThreadService} */
|
||||
this.threadService = services["mail.thread"];
|
||||
/** @type {import("@mail/core/common/store_service").Store} */
|
||||
this.store = services["mail.store"];
|
||||
/** @type {import("@mail/core/common/thread_service").ThreadService} */
|
||||
this.threadService = services["mail.thread"];
|
||||
}
|
||||
|
||||
setup() {
|
||||
@@ -150,6 +150,15 @@ export class DiscussCoreCommon {
|
||||
seenInfo.lastSeenMessage = { id: last_message_id };
|
||||
}
|
||||
});
|
||||
this.busService.subscribe("mail.record/insert", (payload) => {
|
||||
if (payload.Channel) {
|
||||
this.threadService.insert({
|
||||
id: payload.Channel.id,
|
||||
model: "discuss.channel",
|
||||
channel: payload.Channel,
|
||||
});
|
||||
}
|
||||
});
|
||||
this.busService.start();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,6 +60,17 @@ export class DiscussCoreWeb {
|
||||
}
|
||||
}
|
||||
);
|
||||
this.busService.subscribe("mail.record/insert", (payload) => {
|
||||
const { "res.users.settings": settings } = payload;
|
||||
if (settings) {
|
||||
this.store.discuss.chats.isOpen =
|
||||
settings.is_discuss_sidebar_category_chat_open ??
|
||||
this.store.discuss.chats.isOpen;
|
||||
this.store.discuss.channels.isOpen =
|
||||
settings.is_discuss_sidebar_category_channel_open ??
|
||||
this.store.discuss.channels.isOpen;
|
||||
}
|
||||
});
|
||||
this.busService.subscribe("res.users/connection", async ({ partnerId, username }) => {
|
||||
// If the current user invited a new user, and the new user is
|
||||
// connecting for the first time while the current user is present
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { mailCoreCommon } from "@mail/core/common/mail_core_common_service";
|
||||
import { setupManager } from "@mail/../tests/helpers/webclient_setup";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(setupManager, "mail/core/common", {
|
||||
setupServices(...args) {
|
||||
return {
|
||||
...this._super(...args),
|
||||
"mail.core.common": mailCoreCommon,
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user