diff --git a/addons/hr/static/src/core/web/thread_actions.js b/addons/hr/static/src/core/web/thread_actions.js index fa1736acfaa..93db4d07bd5 100644 --- a/addons/hr/static/src/core/web/thread_actions.js +++ b/addons/hr/static/src/core/web/thread_actions.js @@ -26,7 +26,7 @@ threadActionsRegistry.add("open-hr-profile", { async setup(action) { const component = useComponent(); const orm = useService("orm"); - const personaService = useService("mail.persona"); + const store = useService("mail.store"); let employeeId; if (!component.thread?.correspondent?.employeeId && component.thread?.chatPartnerId) { const employees = await orm.silent.searchRead( @@ -37,7 +37,7 @@ threadActionsRegistry.add("open-hr-profile", { employeeId = employees[0]?.id; } if (employeeId) { - personaService.insert({ + store.Persona.insert({ ...component.thread.correspondent, employeeId, }); diff --git a/addons/hr/static/src/thread_service_patch.js b/addons/hr/static/src/thread_service_patch.js index bbced6e6a8c..d0725e10947 100644 --- a/addons/hr/static/src/thread_service_patch.js +++ b/addons/hr/static/src/thread_service_patch.js @@ -34,7 +34,7 @@ const threadServicePatch = { user = this.store.users[employee.user_id]; } user.partner_id = employeeData.user_partner_id[0]; - this.personaService.insert({ + this.store.Persona.insert({ displayName: employeeData.user_partner_id[1], id: employeeData.user_partner_id[0], type: "partner", diff --git a/addons/im_livechat/static/src/composer/suggestion_service_patch.js b/addons/im_livechat/static/src/composer/suggestion_service_patch.js index 3de90bccfb2..9fa578b849f 100644 --- a/addons/im_livechat/static/src/composer/suggestion_service_patch.js +++ b/addons/im_livechat/static/src/composer/suggestion_service_patch.js @@ -31,7 +31,7 @@ patch(SuggestionService.prototype, { }, searchCannedResponseSuggestions(cleanedSearchTerm, sort) { - const cannedResponses = this.store.CannedResponse.records + const cannedResponses = Object.values(this.store.CannedResponse.records) .filter((cannedResponse) => { return cleanTerm(cannedResponse.name).includes(cleanedSearchTerm); }) diff --git a/addons/im_livechat/static/src/core/thread_service_patch.js b/addons/im_livechat/static/src/core/thread_service_patch.js index 409f218c60e..4cb507649a2 100644 --- a/addons/im_livechat/static/src/core/thread_service_patch.js +++ b/addons/im_livechat/static/src/core/thread_service_patch.js @@ -15,7 +15,7 @@ patch(ThreadService.prototype, { assignDefined(thread, data.channel, ["anonymous_name"]); } if (data?.operator_pid) { - thread.operator = this.personaService.insert({ + thread.operator = this.store.Persona.insert({ type: "partner", id: data.operator_pid[0], displayName: data.operator_pid[1], @@ -95,7 +95,7 @@ patch(ThreadService.prototype, { this.setDiscussThread(oldestUnreadThread); return true; } - const chatWindow = this.chatWindowService.insert({ thread: oldestUnreadThread }); + const chatWindow = this.store.ChatWindow.insert({ thread: oldestUnreadThread }); if (chatWindow.hidden) { this.chatWindowService.makeVisible(chatWindow); } else if (chatWindow.folded) { diff --git a/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js b/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js index 4c220049d5a..fcd1beddcdc 100644 --- a/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js +++ b/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js @@ -112,7 +112,7 @@ export class ChatBotService { chatbot_script_id: this.chatbot.scriptId, }); this.livechatService.thread?.messages.push( - this.messageService.insert({ ...message, body: markup(message.body) }) + this.store.Message.insert({ ...message, body: markup(message.body) }) ); this.currentStep = null; this.start(); @@ -127,7 +127,7 @@ export class ChatBotService { chatbot_script_id: this.chatbot.scriptId, }); for (const rawMessage of rawMessages) { - const message = this.messageService.insert({ + const message = this.store.Message.insert({ ...rawMessage, body: markup(rawMessage.body), }); @@ -158,7 +158,7 @@ export class ChatBotService { return; } if (stepMessage) { - const message = this.messageService.insert({ + const message = this.store.Message.insert({ ...stepMessage, body: markup(stepMessage.body), }); @@ -263,7 +263,7 @@ export class ChatBotService { this.currentStep.isEmailValid = success; if (msg && !this.livechatService.thread.messages.some((m) => m.id === msg.id)) { this.livechatService.thread.messages.push( - this.messageService.insert({ ...msg, body: markup(msg.body) }) + this.store.Message.insert({ ...msg, body: markup(msg.body) }) ); } } diff --git a/addons/im_livechat/static/src/embed/core/messaging_service_patch.js b/addons/im_livechat/static/src/embed/core/messaging_service_patch.js index 06982367374..08f38e7aad3 100644 --- a/addons/im_livechat/static/src/embed/core/messaging_service_patch.js +++ b/addons/im_livechat/static/src/embed/core/messaging_service_patch.js @@ -8,7 +8,7 @@ import { session } from "@web/session"; patch(Messaging.prototype, { initialize() { if (session.livechatData?.options.current_partner_id) { - this.store.user = this.personaService.insert({ + this.store.user = this.store.Persona.insert({ type: "partner", id: session.livechatData.options.current_partner_id, }); diff --git a/addons/im_livechat/static/src/embed/core/thread_service_patch.js b/addons/im_livechat/static/src/embed/core/thread_service_patch.js index 24f27024c7a..623986009b7 100644 --- a/addons/im_livechat/static/src/embed/core/thread_service_patch.js +++ b/addons/im_livechat/static/src/embed/core/thread_service_patch.js @@ -100,7 +100,7 @@ patch(ThreadService.prototype, { if (!thread) { return; } - const chatWindow = this.chatWindowService.insert({ + const chatWindow = this.store.ChatWindow.insert({ thread, folded: thread.state === "folded", }); @@ -118,7 +118,7 @@ patch(ThreadService.prototype, { this.livechatService.displayWelcomeMessage && !this.chatbotService.isChatbotThread(thread) ) { - this.livechatService.welcomeMessage = this.messageService.insert({ + this.livechatService.welcomeMessage = this.store.Message.insert({ id: this.messageService.getNextTemporaryId(), body: this.livechatService.options.default_message, res_id: thread.id, @@ -127,7 +127,7 @@ patch(ThreadService.prototype, { }); } if (this.chatbotService.isChatbotThread(thread)) { - this.chatbotService.typingMessage = this.messageService.insert({ + this.chatbotService.typingMessage = this.store.Message.insert({ id: this.messageService.getNextTemporaryId(), res_id: thread.id, model: thread.model, @@ -163,7 +163,7 @@ patch(ThreadService.prototype, { async update(thread, data) { super.update(...arguments); if (data.operator_pid) { - thread.operator = this.personaService.insert({ + thread.operator = this.store.Persona.insert({ type: "partner", id: data.operator_pid[0], name: data.operator_pid[1], @@ -199,7 +199,7 @@ patch(ThreadService.prototype, { this.notification.add(_t("No available collaborator, please try again later.")); return; } - const thread = this.insert({ + const thread = this.store.Thread.insert({ ...session, id: session.id ?? this.TEMPORARY_ID, model: "discuss.channel", @@ -211,7 +211,7 @@ patch(ThreadService.prototype, { message.parentMessage.body = markup(message.parentMessage.body); } message.body = markup(message.body); - return this.messageService.insert(message); + return this.store.Message.insert(message); }); } return thread; diff --git a/addons/mail/static/src/core/common/attachment_service.js b/addons/mail/static/src/core/common/attachment_service.js index 64fcff0dcab..9dab855c953 100644 --- a/addons/mail/static/src/core/common/attachment_service.js +++ b/addons/mail/static/src/core/common/attachment_service.js @@ -56,8 +56,7 @@ export class AttachmentService { const threadData = Array.isArray(data.originThread) ? data.originThread[0][1] : data.originThread; - // this prevents cyclic dependencies between mail.thread and mail.attachment - this.env.bus.trigger("mail.thread/insert", { + this.store.Thread.insert({ model: threadData.model, id: threadData.id, }); diff --git a/addons/mail/static/src/core/common/attachment_upload_service.js b/addons/mail/static/src/core/common/attachment_upload_service.js index eb96d9cea78..200c49edc59 100644 --- a/addons/mail/static/src/core/common/attachment_upload_service.js +++ b/addons/mail/static/src/core/common/attachment_upload_service.js @@ -39,12 +39,12 @@ export class AttachmentUploadService { const threadId = parseInt(upload.data.get("thread_id")); const threadModel = upload.data.get("thread_model"); const tmpUrl = upload.data.get("tmp_url"); - const originThread = this.threadService.insert({ + const originThread = this.store.Thread.insert({ model: threadModel, id: threadId, }); this.abortByAttachmentId.set(tmpId, upload.xhr.abort.bind(upload.xhr)); - const attachment = this.attachmentService.insert( + const attachment = this.store.Attachment.insert( this._makeAttachmentData( upload, tmpId, @@ -87,7 +87,7 @@ export class AttachmentUploadService { const threadModel = upload.data.get("thread_model"); const originThread = this.store.Thread.records[createLocalId(threadModel, threadId)]; - const attachment = this.attachmentService.insert({ + const attachment = this.store.Attachment.insert({ ...response, extension: upload.title.split(".").pop(), originThread: hooker.composer ? undefined : originThread, diff --git a/addons/mail/static/src/core/common/attachment_view.js b/addons/mail/static/src/core/common/attachment_view.js index d04e87d941b..cc933ba62dc 100644 --- a/addons/mail/static/src/core/common/attachment_view.js +++ b/addons/mail/static/src/core/common/attachment_view.js @@ -18,6 +18,7 @@ export class AttachmentView extends Component { setup() { this.threadService = useService("mail.thread"); + this.store = useState(useService("mail.store")); this.iframeViewerPdfRef = useRef("iframeViewerPdf"); this.state = useState({ /** @type {import("@mail/core/common/thread_model").Thread|undefined} */ @@ -53,7 +54,7 @@ export class AttachmentView extends Component { } updateFromProps(props) { - this.state.thread = this.threadService.insert({ + this.state.thread = this.store.Thread.insert({ id: props.threadId, model: props.threadModel, }); diff --git a/addons/mail/static/src/core/common/channel_member_service.js b/addons/mail/static/src/core/common/channel_member_service.js index f37064298f3..20bbfc42e76 100644 --- a/addons/mail/static/src/core/common/channel_member_service.js +++ b/addons/mail/static/src/core/common/channel_member_service.js @@ -36,7 +36,7 @@ export class ChannelMemberService { const [command, memberData] = Array.isArray(data) ? data : ["insert", data]; member.id = memberData.id; if ("persona" in memberData) { - member.persona = this.personaService.insert({ + member.persona = this.store.Persona.insert({ ...(memberData.persona.partner ?? memberData.persona.guest), type: memberData.persona.guest ? "guest" : "partner", country: memberData.persona.partner?.country, @@ -45,8 +45,7 @@ export class ChannelMemberService { } member.threadId = memberData.threadId ?? member.threadId ?? memberData.channel?.id; if (member.threadId && !member.thread) { - // this prevents cyclic dependencies between mail.thread and discuss.channel.member - this.env.bus.trigger("mail.thread/insert", { + this.store.Thread.insert({ id: member.threadId, model: "discuss.channel", }); diff --git a/addons/mail/static/src/core/common/chat_window_service.js b/addons/mail/static/src/core/common/chat_window_service.js index fda3d56b26f..82689dcd3fb 100644 --- a/addons/mail/static/src/core/common/chat_window_service.js +++ b/addons/mail/static/src/core/common/chat_window_service.js @@ -32,7 +32,7 @@ export class ChatWindowService { } open(thread, replaceNewMessageChatWindow) { - const chatWindow = this.insert({ + const chatWindow = this.store.ChatWindow.insert({ folded: false, thread, replaceNewMessageChatWindow, @@ -49,7 +49,7 @@ export class ChatWindowService { // New message chat window is already opened. return; } - this.insert(); + this.store.ChatWindow.insert(); } closeNewMessage() { diff --git a/addons/mail/static/src/core/common/composer.js b/addons/mail/static/src/core/common/composer.js index b8b991181f7..d5894d9ed07 100644 --- a/addons/mail/static/src/core/common/composer.js +++ b/addons/mail/static/src/core/common/composer.js @@ -432,7 +432,7 @@ export class Composer extends Component { }); for (const index in partners) { const partnerData = partners[index]; - const persona = this.personaService.insert({ ...partnerData, type: "partner" }); + const persona = this.store.Persona.insert({ ...partnerData, type: "partner" }); const email = emailsWithoutPartners[index]; const recipient = this.thread.suggestedRecipients.find( (recipient) => recipient.email === email diff --git a/addons/mail/static/src/core/common/mail_core_common_service.js b/addons/mail/static/src/core/common/mail_core_common_service.js index 0c91ed2604e..784779ea693 100644 --- a/addons/mail/static/src/core/common/mail_core_common_service.js +++ b/addons/mail/static/src/core/common/mail_core_common_service.js @@ -29,7 +29,7 @@ export class MailCoreCommon { this.busService.subscribe("ir.attachment/delete", (payload) => { const { id: attachmentId, message: messageData } = payload; if (messageData) { - this.messageService.insert({ ...messageData }); + this.store.Message.insert({ ...messageData }); } const attachment = this.store.Attachment.records[attachmentId]; if (attachment) { @@ -63,7 +63,7 @@ export class MailCoreCommon { }); this.busService.subscribe("mail.message/notification_update", (payload) => { payload.elements.map((message) => { - this.messageService.insert({ + this.store.Message.insert({ ...message, body: markup(message.body), // implicit: failures are sent by the server at @@ -76,13 +76,13 @@ export class MailCoreCommon { this.busService.subscribe("mail.message/toggle_star", (payload) => { const { message_ids: messageIds, starred } = payload; for (const messageId of messageIds) { - const message = this.messageService.insert({ id: messageId }); + const message = this.store.Message.insert({ id: messageId }); this.messageService.updateStarred(message, starred); } }); this.busService.subscribe("mail.record/insert", (payload) => { if (payload.Thread) { - this.threadService.insert(payload.Thread); + this.store.Thread.insert(payload.Thread); } if (payload.Partner) { const partners = Array.isArray(payload.Partner) @@ -90,14 +90,14 @@ export class MailCoreCommon { : [payload.Partner]; for (const partner of partners) { if (partner.im_status) { - this.personaService.insert({ ...partner, type: "partner" }); + this.store.Persona.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" }); + this.store.Persona.insert({ ...guest, type: "guest" }); } } const { LinkPreview: linkPreviews } = payload; @@ -111,7 +111,7 @@ export class MailCoreCommon { const { Message: messageData } = payload; if (messageData) { const isStarred = this.store.Message.records[messageData.id]?.isStarred; - const message = this.messageService.insert({ + const message = this.store.Message.insert({ ...messageData, body: messageData.body ? markup(messageData.body) : messageData.body, }); diff --git a/addons/mail/static/src/core/common/message.js b/addons/mail/static/src/core/common/message.js index 8ddd5afd0ed..1ca7af5bf5e 100644 --- a/addons/mail/static/src/core/common/message.js +++ b/addons/mail/static/src/core/common/message.js @@ -333,7 +333,7 @@ export class Message extends Component { const id = Number(ev.target.dataset.oeId); if (ev.target.closest(".o_channel_redirect")) { ev.preventDefault(); - const thread = this.threadService.insert({ model, id }); + const thread = this.store.Thread.insert({ model, id }); this.threadService.open(thread); return; } diff --git a/addons/mail/static/src/core/common/message_service.js b/addons/mail/static/src/core/common/message_service.js index 918953f453a..0302c8cfa76 100644 --- a/addons/mail/static/src/core/common/message_service.js +++ b/addons/mail/static/src/core/common/message_service.js @@ -47,7 +47,7 @@ export class MessageService { message_id: message.id, partner_ids: validMentions?.partners?.map((partner) => partner.id), }); - this.insert( + this.store.Message.insert( Object.assign(messageData, { body: messageData.body ? markup(messageData.body) : messageData.body, }) @@ -133,7 +133,7 @@ export class MessageService { createTransient(data) { const { body, res_id, model } = data; const lastMessageId = this.getLastMessageId(); - return this.insert({ + return this.store.Message.insert({ author: this.store.odoobot, body, id: lastMessageId + 0.01, @@ -216,8 +216,7 @@ export class MessageService { insert(data) { let message; if (data.res_id) { - // this prevents cyclic dependencies between mail.thread and mail.message - this.env.bus.trigger("mail.thread/insert", { + this.store.Thread.insert({ model: data.model, id: data.res_id, }); @@ -268,7 +267,7 @@ export class MessageService { ? message.starred_partner_ids.includes(this.store.user.id) : false, isTransient, - parentMessage: parentMessage ? this.insert(parentMessage) : undefined, + parentMessage: parentMessage ? this.store.Message.insert(parentMessage) : undefined, resId, resModel, subtypeDescription, @@ -285,7 +284,7 @@ export class MessageService { replaceArrayWithCompare( message.attachments, attachments.map((attachment) => - this.attachmentService.insert({ message, ...attachment }) + this.store.Attachment.insert({ message, ...attachment }) ) ); if ( @@ -295,13 +294,13 @@ export class MessageService { message.author = undefined; } if (data.author?.id) { - message.author = this.personaService.insert({ + message.author = this.store.Persona.insert({ ...data.author, type: "partner", }); } if (data.guestAuthor?.id) { - message.author = this.personaService.insert({ + message.author = this.store.Persona.insert({ ...data.guestAuthor, type: "guest", channelId: message.originThread.id, @@ -314,17 +313,17 @@ export class MessageService { replaceArrayWithCompare( message.notifications, notifications.map((notification) => - this.insertNotification({ ...notification, messageId: message.id }) + this.store.Notification.insert({ ...notification, messageId: message.id }) ) ); replaceArrayWithCompare( message.recipients, recipients.map((recipient) => - this.personaService.insert({ ...recipient, type: "partner" }) + this.store.Persona.insert({ ...recipient, type: "partner" }) ) ); if ("user_follower_id" in data && data.user_follower_id && this.store.self) { - message.originThread.selfFollower = this.env.services["mail.thread"].insertFollower({ + message.originThread.selfFollower = this.env.services["mail.store"].Follower.insert({ followedThread: message.originThread, id: data.user_follower_id, isActive: true, @@ -402,7 +401,7 @@ export class MessageService { const [command, partnerData] = Array.isArray(rawPartner) ? rawPartner : ["insert", rawPartner]; - const persona = this.personaService.insert({ ...partnerData, type: "partner" }); + const persona = this.store.Persona.insert({ ...partnerData, type: "partner" }); if (command === "insert" && !alreadyKnownPersonaIds.has(persona.localId)) { reaction.personaLocalIds.push(persona.localId); } else if (command !== "insert") { @@ -411,7 +410,7 @@ export class MessageService { } for (const rawGuest of data.guests) { const [command, guestData] = Array.isArray(rawGuest) ? rawGuest : ["insert", rawGuest]; - const persona = this.personaService.insert({ ...guestData, type: "guest" }); + const persona = this.store.Persona.insert({ ...guestData, type: "guest" }); if (command === "insert" && !alreadyKnownPersonaIds.has(persona.localId)) { reaction.personaLocalIds.push(persona.localId); } else if (command !== "insert") { @@ -450,7 +449,7 @@ export class MessageService { notification_type: data.notification_type, failure_type: data.failure_type, persona: data.res_partner_id - ? this.personaService.insert({ + ? this.store.Persona.insert({ id: data.res_partner_id[0], displayName: data.res_partner_id[1], type: "partner", @@ -461,7 +460,7 @@ export class MessageService { return; } const thread = notification.message.originThread; - this.insertNotificationGroups({ + this.store.NotificationGroup.insert({ modelName: thread?.modelName, resId: thread?.id, resModel: thread?.model, diff --git a/addons/mail/static/src/core/common/messaging_service.js b/addons/mail/static/src/core/common/messaging_service.js index 0de8527b282..c5aa756dad9 100644 --- a/addons/mail/static/src/core/common/messaging_service.js +++ b/addons/mail/static/src/core/common/messaging_service.js @@ -30,23 +30,23 @@ export class Messaging { this.isReady = new Deferred(); this.imStatusService = services.im_status; const user = services.user; - this.personaService.insert({ id: user.partnerId, type: "partner", isAdmin: user.isAdmin }); + this.store.Persona.insert({ id: user.partnerId, type: "partner", isAdmin: user.isAdmin }); this.registeredImStatusPartners = reactive([], () => this.updateImStatusRegistration()); this.store.registeredImStatusPartners = this.registeredImStatusPartners; - this.store.discuss.inbox = this.threadService.insert({ + this.store.discuss.inbox = this.store.Thread.insert({ id: "inbox", model: "mail.box", name: _t("Inbox"), type: "mailbox", }); - this.store.discuss.starred = this.threadService.insert({ + this.store.discuss.starred = this.store.Thread.insert({ id: "starred", model: "mail.box", name: _t("Starred"), type: "mailbox", counter: 0, }); - this.store.discuss.history = this.threadService.insert({ + this.store.discuss.history = this.store.Thread.insert({ id: "history", model: "mail.box", name: _t("History"), @@ -67,19 +67,19 @@ export class Messaging { initMessagingCallback(data) { if (data.current_partner) { - this.store.user = this.personaService.insert({ + this.store.user = this.store.Persona.insert({ ...data.current_partner, type: "partner", }); } if (data.currentGuest) { - this.store.guest = this.personaService.insert({ + this.store.guest = this.store.Persona.insert({ ...data.currentGuest, type: "guest", channelId: data.channels[0]?.id, }); } - this.store.odoobot = this.personaService.insert({ + this.store.odoobot = this.store.Persona.insert({ ...data.odoobot, type: "partner", }); @@ -94,7 +94,7 @@ export class Messaging { data.menu_id === this.router.current.hash?.menu_id || this.router.hash?.action === "mail.action_discuss"; (data.shortcodes ?? []).forEach((code) => { - this.insertCannedResponse(code); + this.store.CannedResponse.insert(code); }); this.store.hasLinkPreviewFeature = data.hasLinkPreviewFeature; this.store.initBusId = data.initBusId; @@ -145,7 +145,7 @@ export class Messaging { limit, ]); partners = partnersData.map((data) => - this.personaService.insert({ ...data, type: "partner" }) + this.store.Persona.insert({ ...data, type: "partner" }) ); } return partners; diff --git a/addons/mail/static/src/core/common/store_service.js b/addons/mail/static/src/core/common/store_service.js index 804392185fa..80e17b8cbed 100644 --- a/addons/mail/static/src/core/common/store_service.js +++ b/addons/mail/static/src/core/common/store_service.js @@ -12,48 +12,113 @@ export class Store { Activity = { /** @type {Object.} */ records: {}, + /** + * @param {import("@mail/core/web/activity_model").Data} data + * @param {Object} [param1] + * @param {boolean} param1.broadcast + * @returns {import("@mail/core/web/activity_model").Activity} + */ + insert: (data, { broadcast = true } = {}) => + this.env.services["mail.activity"].insert(data, { broadcast }), }; Attachment = { /** @type {Object.} */ records: {}, + /** + * @param {Object} data + * @returns {import("@mail/core/common/attachment_model").Attachment} + */ + insert: (data) => this.env.services["mail.attachment"].insert(data), }; CannedResponse = { - records: [], + /** @type {Object.} */ + records: {}, + /** + * @param {Object} data + * @returns {import("@mail/core/common/canned_response_model").CannedResponse} + */ + insert: (data) => this.env.services["mail.messaging"].insertCannedResponse(data), }; ChannelMember = { /** @type {Object.} */ records: {}, + /** + * @param {Object|Array} data + * @returns {import("@mail/core/common/channel_member_model").ChannelMember} + */ + insert: (data) => this.env.services["discuss.channel.member"].insert(data), }; ChatWindow = { /** @type {import("@mail/core/common/chat_window_model").ChatWindow[]} */ records: [], + /** + * @param {ChatWindowData} [data] + * @returns {import("@mail/core/common/chat_window_model").ChatWindow} + */ + insert: (data = {}) => this.env.services["mail.chat_window"].insert(data), }; Follower = { /** @type {Object.} */ records: {}, + /** + * @param {import("@mail/core/common/follower_model").Data} data + * @returns {import("@mail/core/common/follower_model").Follower} + */ + insert: (data) => this.env.services["mail.thread"].insertFollower(data), }; Message = { /** @type {Object.} */ records: {}, + /** + * @param {Object} data + * @returns {import("@mail/core/common/message_model").Message} + */ + insert: (data) => this.env.services["mail.message"].insert(data), }; Notification = { /** @type {Object.} */ records: {}, + /** + * @param {Object} data + * @returns {import("@mail/core/common/notification_model").Notification} + */ + insert: (data) => this.env.services["mail.message"].insertNotification(data), }; NotificationGroup = { + /** @type {import("@mail/core/common/notification_group_model").NotificationGroup[]} */ records: [], + /** + * @param {Object} data + * @returns {import("@mail/core/common/notification_group_model").NotificationGroup} + */ + insert: (data) => this.env.services["mail.message"].insertNotificationGroups(data), }; Persona = { /** @type {Object.} */ records: {}, + /** + * @param {import("@mail/core/common/persona_model").Data} data + * @returns {import("@mail/core/common/persona_model").Persona} + */ + insert: (data) => this.env.services["mail.persona"].insert(data), }; RtcSession = { /** @type {Object.} */ records: {}, + /** + * @param {Object} data + * @returns {number, import("@mail/discuss/call/common/rtc_session_model").RtcSession} + */ + insert: (data) => this.env.services["discuss.rtc"].insertSession(data), }; Thread = { /** @type {Object.} */ records: {}, + /** + * @param {Object} data + * @returns {import("@mail/core/common/thread_model").Thread} + */ + insert: (data) => this.env.services["mail.thread"].insert(data), }; /** diff --git a/addons/mail/static/src/core/common/suggestion_service.js b/addons/mail/static/src/core/common/suggestion_service.js index 7ed2bfadbb1..3b65a9c9c4b 100644 --- a/addons/mail/static/src/core/common/suggestion_service.js +++ b/addons/mail/static/src/core/common/suggestion_service.js @@ -54,9 +54,9 @@ export class SuggestionService { kwargs ); suggestedPartners.map((data) => { - this.personaService.insert({ ...data, type: "partner" }); + this.store.Persona.insert({ ...data, type: "partner" }); if (data.persona?.channelMembers) { - this.channelMemberService.insert(...data.persona.channelMembers); + this.store.ChannelMember.insert(...data.persona.channelMembers); } }); } @@ -72,7 +72,7 @@ export class SuggestionService { { search: term } ); suggestedThreads.map((data) => { - this.threadService.insert({ + this.store.Thread.insert({ model: "discuss.channel", ...data, }); diff --git a/addons/mail/static/src/core/common/thread_service.js b/addons/mail/static/src/core/common/thread_service.js index 2828a7bae00..70ab0dd511f 100644 --- a/addons/mail/static/src/core/common/thread_service.js +++ b/addons/mail/static/src/core/common/thread_service.js @@ -53,13 +53,6 @@ export class ThreadService { this.ui = services.ui; this.personaService = services["mail.persona"]; this.messageService = services["mail.message"]; - // this prevents cyclic dependencies between mail.thread and other services - this.env.bus.addEventListener("mail.thread/insert", ({ detail }) => { - const model = detail.model; - const id = detail.id; - const type = detail.type; - this.insert({ model, id, type }); - }); } /** @@ -69,7 +62,7 @@ export class ThreadService { */ async fetchChannel(id) { const [channelData] = await this.rpc("/discuss/channel/info", { channel_id: id }); - return this.insert({ + return this.store.Thread.insert({ ...channelData, model: "discuss.channel", type: channelData.channel.channel_type, @@ -93,7 +86,7 @@ export class ThreadService { thread.memberCount = results["memberCount"]; for (const channelMember of channelMembers) { if (channelMember.persona || channelMember.partner) { - this.channelMemberService.insert({ ...channelMember, threadId: thread.id }); + this.store.ChannelMember.insert({ ...channelMember, threadId: thread.id }); } } } @@ -218,7 +211,7 @@ export class ThreadService { ? markup(data.parentMessage.body) : data.parentMessage.body; } - return this.messageService.insert( + return this.store.Message.insert( Object.assign(data, { body: data.body ? markup(data.body) : data.body }) ); }); @@ -324,7 +317,7 @@ export class ThreadService { if (message.parentMessage?.body) { message.parentMessage.body = markup(message.parentMessage.body); } - return this.messageService.insert({ + return this.store.Message.insert({ ...message, body: message.body ? markup(message.body) : message.body, }); @@ -361,7 +354,7 @@ export class ThreadService { const data = Object.assign(preview.last_message, { body: markup(preview.last_message.body), }); - const message = this.messageService.insert({ + const message = this.store.Message.insert({ ...data, res_id: thread.id, model: thread.model, @@ -520,7 +513,7 @@ export class ThreadService { } if (partnerId) { - const partner = this.personaService.insert({ id: partnerId, type: "partner" }); + const partner = this.store.Persona.insert({ id: partnerId, type: "partner" }); if (!partner.user) { const [userId] = await this.orm.silent.search( "res.users", @@ -580,7 +573,7 @@ export class ThreadService { await this.orm.call("discuss.channel", "add_members", [[id]], { partner_ids: [this.store.user.id], }); - const thread = this.insert({ + const thread = this.store.Thread.insert({ id, model: "discuss.channel", name, @@ -596,7 +589,7 @@ export class ThreadService { const data = await this.orm.call("discuss.channel", "channel_get", [], { partners_to: [id], }); - return this.insert({ + return this.store.Thread.insert({ ...data, model: "discuss.channel", type: "chat", @@ -737,7 +730,7 @@ export class ThreadService { for (const [command, membersData] of serverData.channel.channelMembers) { const members = Array.isArray(membersData) ? membersData : [membersData]; for (const memberData of members) { - const member = this.channelMemberService.insert([command, memberData]); + const member = this.store.ChannelMember.insert([command, memberData]); if (thread.type !== "chat") { continue; } @@ -762,7 +755,7 @@ export class ThreadService { case "insert": if (members) { for (const member of members) { - const record = this.channelMemberService.insert(member); + const record = this.store.ChannelMember.insert(member); thread.invitedMemberIds.add(record.id); } } @@ -781,12 +774,12 @@ export class ThreadService { ({ fetched_message_id, partner_id, seen_message_id }) => { return { lastFetchedMessage: fetched_message_id - ? this.messageService.insert({ id: fetched_message_id }) + ? this.store.Message.insert({ id: fetched_message_id }) : undefined, lastSeenMessage: seen_message_id - ? this.messageService.insert({ id: seen_message_id }) + ? this.store.Message.insert({ id: seen_message_id }) : undefined, - partner: this.personaService.insert({ + partner: this.store.Persona.insert({ id: partner_id, type: "partner", }), @@ -933,7 +926,7 @@ export class ThreadService { } } browser.localStorage.setItem("web.emoji.frequent", JSON.stringify(recentEmojis)); - tmpMsg = this.messageService.insert({ + tmpMsg = this.store.Message.insert({ ...tmpData, body: markup(prettyContent), res_id: thread.id, @@ -959,9 +952,7 @@ export class ThreadService { if (data.id in this.store.Message.records) { data.temporary_id = null; } - const message = this.messageService.insert( - Object.assign(data, { body: markup(data.body) }) - ); + const message = this.store.Message.insert(Object.assign(data, { body: markup(data.body) })); if (message.notIn(thread.messages)) { thread.messages.push(message); } diff --git a/addons/mail/static/src/core/web/activity_service.js b/addons/mail/static/src/core/web/activity_service.js index cd39be837a7..eb6ad68f464 100644 --- a/addons/mail/static/src/core/web/activity_service.js +++ b/addons/mail/static/src/core/web/activity_service.js @@ -111,7 +111,7 @@ export class ActivityService { _onBroadcastChannelMessage({ data }) { switch (data.type) { case "insert": - this.insert(data.payload, { broadcast: false }); + this.store.Activity.insert(data.payload, { broadcast: false }); break; case "delete": this.delete(data.payload, { broadcast: false }); diff --git a/addons/mail/static/src/core/web/chatter.js b/addons/mail/static/src/core/web/chatter.js index c6c07e46acd..d0bca88218a 100644 --- a/addons/mail/static/src/core/web/chatter.js +++ b/addons/mail/static/src/core/web/chatter.js @@ -140,7 +140,7 @@ export class Chatter extends Component { onPatched(this.scrollPosition.restore); onWillStart(() => { if (this.props.threadId) { - this.state.thread = this.threadService.insert({ + this.state.thread = this.store.Thread.insert({ id: this.props.threadId, model: this.props.threadModel, name: this.props.webRecord?.data?.display_name || undefined, diff --git a/addons/mail/static/src/core/web/mail_core_web_service.js b/addons/mail/static/src/core/web/mail_core_web_service.js index 845aba36acf..598a1aa271d 100644 --- a/addons/mail/static/src/core/web/mail_core_web_service.js +++ b/addons/mail/static/src/core/web/mail_core_web_service.js @@ -24,7 +24,7 @@ export class MailCoreWeb { this.messagingService.isReady.then(() => { this.rpc("/mail/load_message_failures", {}, { silent: true }).then((messages) => { messages.map((messageData) => - this.messageService.insert({ + this.store.Message.insert({ ...messageData, body: messageData.body ? markup(messageData.body) : messageData.body, // implicit: failures are sent by the server at @@ -71,7 +71,7 @@ export class MailCoreWeb { }); this.busService.subscribe("mail.message/inbox", (payload) => { const data = Object.assign(payload, { body: markup(payload.body) }); - const message = this.messageService.insert(data); + const message = this.store.Message.insert(data); const inbox = this.store.discuss.inbox; if (message.notIn(inbox.messages)) { inbox.messages.push(message); diff --git a/addons/mail/static/src/core/web/thread_service_patch.js b/addons/mail/static/src/core/web/thread_service_patch.js index 93d3149671d..022fbc3bf18 100644 --- a/addons/mail/static/src/core/web/thread_service_patch.js +++ b/addons/mail/static/src/core/web/thread_service_patch.js @@ -57,7 +57,7 @@ patch(ThreadService.prototype, { if (activity.note) { activity.note = markup(activity.note); } - existingIds.add(this.activityService.insert(activity).id); + existingIds.add(this.store.Activity.insert(activity).id); } for (const activity of thread.activities) { if (!existingIds.has(activity.id)) { @@ -74,7 +74,7 @@ patch(ThreadService.prototype, { } if ("mainAttachment" in result) { thread.mainAttachment = result.mainAttachment.id - ? this.attachmentService.insert(result.mainAttachment) + ? this.store.Attachment.insert(result.mainAttachment) : undefined; } if (!thread.mainAttachment && thread.attachmentsInWebClientView.length > 0) { @@ -82,14 +82,14 @@ patch(ThreadService.prototype, { } if ("followers" in result) { if (result.selfFollower) { - thread.selfFollower = this.insertFollower({ + thread.selfFollower = this.store.Follower.insert({ followedThread: thread, ...result.selfFollower, }); } thread.followersCount = result.followersCount; for (const followerData of result.followers) { - const follower = this.insertFollower({ + const follower = this.store.Follower.insert({ followedThread: thread, ...followerData, }); @@ -128,7 +128,7 @@ patch(ThreadService.prototype, { res_id: thread.id, model: thread.model, }; - const message = this.messageService.insert(tmpData); + const message = this.store.Message.insert(tmpData); thread.messages.push(message); } return thread; @@ -147,7 +147,7 @@ patch(ThreadService.prototype, { followedThread: data.followedThread, id: data.id, isActive: data.is_active, - partner: this.personaService.insert({ ...data.partner, type: "partner" }), + partner: this.store.Persona.insert({ ...data.partner, type: "partner" }), _store: this.store, }); return follower; @@ -168,7 +168,7 @@ patch(ThreadService.prototype, { lang, reason, persona: partner_id - ? this.personaService.insert({ + ? this.store.Persona.insert({ type: "partner", id: partner_id, }) @@ -193,7 +193,7 @@ patch(ThreadService.prototype, { Array.from(thread.followers).at(-1).id, ]); for (const data of followers) { - const follower = this.insertFollower({ + const follower = this.store.Follower.insert({ followedThread: thread, ...data, }); @@ -248,7 +248,7 @@ patch(ThreadService.prototype, { super.unpin(...arguments); }, _openChatWindow(thread, replaceNewMessageChatWindow) { - const chatWindow = this.chatWindowService.insert({ + const chatWindow = this.store.ChatWindow.insert({ folded: false, thread, replaceNewMessageChatWindow, diff --git a/addons/mail/static/src/discuss/call/common/rtc_service.js b/addons/mail/static/src/discuss/call/common/rtc_service.js index dfae9f40600..4876f3b0964 100644 --- a/addons/mail/static/src/discuss/call/common/rtc_service.js +++ b/addons/mail/static/src/discuss/call/common/rtc_service.js @@ -174,7 +174,7 @@ export class Rtc { "RTC-SERVICE:UPDATE_RTC_SESSIONS", ({ detail: { commands = [], record, thread } }) => { if (record) { - const session = this.insertSession(record); + const session = this.store.RtcSession.insert(record); thread.rtcSessions[session.id] = session; } for (const command of commands) { @@ -187,7 +187,7 @@ export class Rtc { break; case "insert": for (const rtcSessionData of sessionsData) { - const session = this.insertSession(rtcSessionData); + const session = this.store.RtcSession.insert(rtcSessionData); thread.rtcSessions[session.id] = session; } break; @@ -898,7 +898,7 @@ export class Rtc { if (this.state.channel && rtcSessions) { const activeSessionsData = rtcSessions[0][1]; for (const sessionData of activeSessionsData) { - const session = this.insertSession(sessionData); + const session = this.store.RtcSession.insert(sessionData); this.state.channel.rtcSessions[session.id] = session; } const outdatedSessionsData = rtcSessions[1][1]; @@ -1420,7 +1420,7 @@ export class Rtc { session.channelId = channelMember.channel.id; } if (channelMember) { - const channelMemberRecord = this.channelMemberService.insert(channelMember); + const channelMemberRecord = this.store.ChannelMember.insert(channelMember); channelMemberRecord.rtcSessionId = session.id; session.channelMemberId = channelMemberRecord.id; if (channelMemberRecord.thread) { @@ -1520,7 +1520,7 @@ export class Rtc { break; case "insert": for (const sessionData of sessionsData) { - const session = this.insertSession(sessionData); + const session = this.store.RtcSession.insert(sessionData); channel.rtcSessions[session.id] = session; } break; @@ -1583,7 +1583,7 @@ export const rtcService = { }); services["bus_service"].subscribe("mail.record/insert", (payload) => { if (payload.RtcSession) { - rtc.insertSession(payload.RtcSession); + rtc.store.RtcSession.insert(payload.RtcSession); } const { "res.users.settings.volumes": volumeSettings } = payload; if (volumeSettings) { diff --git a/addons/mail/static/src/discuss/core/common/channel_invitation.js b/addons/mail/static/src/discuss/core/common/channel_invitation.js index 77d33c131fc..9722aa9e3bc 100644 --- a/addons/mail/static/src/discuss/core/common/channel_invitation.js +++ b/addons/mail/static/src/discuss/core/common/channel_invitation.js @@ -59,7 +59,7 @@ export class ChannelInvitation extends Component { const Partners = results["partners"]; const selectablePartners = []; for (const selectablePartner of Partners) { - const newPartner = this.personaService.insert({ + const newPartner = this.store.Persona.insert({ type: "partner", ...selectablePartner, }); diff --git a/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js b/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js index b496002834d..2b399f74c9a 100644 --- a/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js +++ b/addons/mail/static/src/discuss/core/common/discuss_core_common_service.js @@ -36,7 +36,7 @@ export class DiscussCoreCommon { this.threadService.sortChannels(); this.busService.subscribe("discuss.channel/joined", (payload) => { const { channel, invited_by_user_id: invitedByUserId } = payload; - const thread = this.threadService.insert({ + const thread = this.store.Thread.insert({ ...channel, model: "discuss.channel", channel: channel.channel, @@ -60,7 +60,7 @@ export class DiscussCoreCommon { } }); this.busService.subscribe("discuss.channel/leave", (payload) => { - const thread = this.threadService.insert({ + const thread = this.store.Thread.insert({ ...payload, model: "discuss.channel", }); @@ -73,7 +73,7 @@ export class DiscussCoreCommon { }); }); this.busService.subscribe("discuss.channel/legacy_insert", (payload) => { - this.threadService.insert({ + this.store.Thread.insert({ id: payload.channel.id, model: "discuss.channel", type: payload.channel.channel_type, @@ -157,7 +157,7 @@ export class DiscussCoreCommon { }); this.busService.subscribe("mail.record/insert", (payload) => { if (payload.Channel) { - this.threadService.insert({ + this.store.Thread.insert({ id: payload.Channel.id, model: "discuss.channel", channel: payload.Channel, @@ -168,12 +168,12 @@ export class DiscussCoreCommon { } /** - * todo: merge this with ThreadService.insert() (?) + * todo: merge this with store.Thread.insert() (?) * * @returns {Thread} */ createChannelThread(serverData) { - const thread = this.threadService.insert({ + const thread = this.store.Thread.insert({ ...serverData, model: "discuss.channel", type: serverData.channel.channel_type, @@ -220,7 +220,7 @@ export class DiscussCoreCommon { let channel = this.store.Thread.records[createLocalId("discuss.channel", id)]; if (!channel || !channel.type) { const [channelData] = await this.rpc("/discuss/channel/info", { channel_id: id }); - channel = this.threadService.insert({ + channel = this.store.Thread.insert({ model: "discuss.channel", type: channelData.channel.channel_type, ...channelData, @@ -238,7 +238,7 @@ export class DiscussCoreCommon { const data = Object.assign(messageData, { body: markup(messageData.body), }); - const message = this.messageService.insert({ + const message = this.store.Message.insert({ ...data, res_id: channel.id, model: channel.model, diff --git a/addons/mail/static/src/discuss/core/public/discuss_public.js b/addons/mail/static/src/discuss/core/public/discuss_public.js index 1a8b5537ea7..13bf2481842 100644 --- a/addons/mail/static/src/discuss/core/public/discuss_public.js +++ b/addons/mail/static/src/discuss/core/public/discuss_public.js @@ -44,7 +44,7 @@ export class DiscussPublic extends Component { } get thread() { - return this.threadService.insert({ + return this.store.Thread.insert({ id: this.props.data.channelData.id, model: "discuss.channel", type: this.props.data.channelData.channel.channel_type, diff --git a/addons/mail/static/src/discuss/core/web/channel_selector.js b/addons/mail/static/src/discuss/core/web/channel_selector.js index b24e3e49c09..6eb22675fff 100644 --- a/addons/mail/static/src/discuss/core/web/channel_selector.js +++ b/addons/mail/static/src/discuss/core/web/channel_selector.js @@ -123,7 +123,7 @@ export class ChannelSelector extends Component { const suggestions = this.suggestionService .sortPartnerSuggestions(results, cleanedTerm) .map((data) => { - this.personaService.insert({ ...data, type: "partner" }); + this.store.Persona.insert({ ...data, type: "partner" }); return { classList: "o-discuss-ChannelSelector-suggestion", label: data.name, diff --git a/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js b/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js index 3371cb347fb..87af64b1274 100644 --- a/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js +++ b/addons/mail/static/src/discuss/core/web/discuss_core_web_service.js @@ -32,7 +32,7 @@ export class DiscussCoreWeb { channelData.state !== "closed" && !this.ui.isSmall ) { - this.chatWindowService.insert({ + this.store.ChatWindow.insert({ autofocus: 0, folded: channelData.state === "folded", thread, @@ -56,7 +56,7 @@ export class DiscussCoreWeb { this.store.odoobotOnboarding = false; return; } - this.chatWindowService.insert({ thread: channel }); + this.store.ChatWindow.insert({ thread: channel }); } ); this.busService.subscribe("mail.record/insert", (payload) => { @@ -81,7 +81,7 @@ export class DiscussCoreWeb { this.notificationService.add(notification, { type: "info" }); const chat = await this.threadService.getChat({ partnerId }); if (chat && !this.ui.isSmall) { - this.chatWindowService.insert({ thread: chat }); + this.store.ChatWindow.insert({ thread: chat }); } }); this.busService.subscribe("mail.record/insert", async (payload) => { @@ -98,7 +98,7 @@ export class DiscussCoreWeb { this.chatWindowService.close(chatWindow); } } else { - this.chatWindowService.insert({ + this.store.ChatWindow.insert({ thread, folded: thread.state === "folded", }); diff --git a/addons/mail/static/src/discuss/message_pin/common/message_pin_service.js b/addons/mail/static/src/discuss/message_pin/common/message_pin_service.js index 46c5ea4cc3a..617eb9adb70 100644 --- a/addons/mail/static/src/discuss/message_pin/common/message_pin_service.js +++ b/addons/mail/static/src/discuss/message_pin/common/message_pin_service.js @@ -87,7 +87,7 @@ export class MessagePin { messageData.parentMessage.body = markup(messageData.parentMessage.body); } messageData.body = markup(messageData.body); - this.messageService.insert(messageData); + this.storeService.Message.insert(messageData); }); this.loadStateByChannelId.set(channel.id, "loaded"); } catch (e) { @@ -111,7 +111,7 @@ export class MessagePin { */ getPinnedMessages(channel) { return [...(this.messageIdsByChannelId.get(channel.id) ?? new Set())] - .map((id) => this.messageService.insert({ id })) + .map((id) => this.storeService.Message.insert({ id })) .sort((a, b) => { const aPinnedAt = this.pinnedAtByMessageId.get(a.id); const bPinnedAt = this.pinnedAtByMessageId.get(b.id); diff --git a/addons/mail/static/src/discuss/typing/common/typing_service.js b/addons/mail/static/src/discuss/typing/common/typing_service.js index de93f958167..7ad872c1871 100644 --- a/addons/mail/static/src/discuss/typing/common/typing_service.js +++ b/addons/mail/static/src/discuss/typing/common/typing_service.js @@ -30,7 +30,7 @@ export class Typing { setup() { this.busService.subscribe("discuss.channel.member/typing_status", (payload) => { - const member = this.channelMemberService.insert(payload); + const member = this.storeService.ChannelMember.insert(payload); if (payload.isTyping) { this.addTypingMember(member); } else { @@ -61,7 +61,7 @@ export class Typing { */ getTypingMembers(channel) { return [...(this.memberIdsByChannelId.get(channel.id) ?? new Set())] - .map((id) => this.channelMemberService.insert({ id })) + .map((id) => this.storeService.ChannelMember.insert({ id })) .filter((member) => !member.persona?.eq(this.storeService.self)); } diff --git a/addons/mail/static/src/views/web/form/form_renderer.js b/addons/mail/static/src/views/web/form/form_renderer.js index d7bfd29569b..c8e3e092e3c 100644 --- a/addons/mail/static/src/views/web/form/form_renderer.js +++ b/addons/mail/static/src/views/web/form/form_renderer.js @@ -23,8 +23,8 @@ patch(FormRenderer.prototype, { /** @type {import("@mail/core/common/thread_model").Thread} */ thread: undefined, }); - if (this.env.services["mail.thread"]) { - this.threadService = useService("mail.thread"); + if (this.env.services["mail.store"]) { + this.mailStore = useService("mail.store"); } this.uiService = useService("ui"); @@ -36,10 +36,10 @@ patch(FormRenderer.prototype, { * @returns {boolean} */ hasFileViewer() { - if (!this.threadService || this.uiService.size < SIZES.XXL || !this.props.record.resId) { + if (!this.mailStore || this.uiService.size < SIZES.XXL || !this.props.record.resId) { return false; } - this.messagingState.thread = this.threadService.insert({ + this.messagingState.thread = this.mailStore.Thread.insert({ id: this.props.record.resId, model: this.props.record.resModel, type: "chatter", diff --git a/addons/mrp/static/src/views/mrp_documents_kanban/mrp_documents_kanban_record.js b/addons/mrp/static/src/views/mrp_documents_kanban/mrp_documents_kanban_record.js index 33661e9047b..065fc076176 100644 --- a/addons/mrp/static/src/views/mrp_documents_kanban/mrp_documents_kanban_record.js +++ b/addons/mrp/static/src/views/mrp_documents_kanban/mrp_documents_kanban_record.js @@ -7,7 +7,7 @@ import { useFileViewer } from "@web/core/file_viewer/file_viewer_hook"; export class MrpDocumentsKanbanRecord extends KanbanRecord { setup() { super.setup(); - this.attachmentService = useService("mail.attachment"); + this.store = useService("mail.store"); this.fileViewer = useFileViewer(); } /** @@ -23,7 +23,7 @@ export class MrpDocumentsKanbanRecord extends KanbanRecord { window.location = `/web/content/mrp.document/${this.props.record.resId}/datas?download=true`; return; } else if (ev.target.closest(".o_kanban_previewer")) { - const attachment = this.attachmentService.insert({ + const attachment = this.store.Attachment.insert({ id: this.props.record.data.ir_attachment_id[0], filename: this.props.record.data.name, name: this.props.record.data.name, diff --git a/addons/website_livechat/static/src/core/thread_service_patch.js b/addons/website_livechat/static/src/core/thread_service_patch.js index 19c4c623b12..62bd9922691 100644 --- a/addons/website_livechat/static/src/core/thread_service_patch.js +++ b/addons/website_livechat/static/src/core/thread_service_patch.js @@ -9,7 +9,7 @@ patch(ThreadService.prototype, { update(thread, data) { super.update(thread, data); if (data?.visitor) { - thread.visitor = this.personaService.insert({ + thread.visitor = this.store.Persona.insert({ ...data.visitor, type: "visitor", }); diff --git a/addons/website_livechat/static/src/core/website_livechat_notification_handler.js b/addons/website_livechat/static/src/core/website_livechat_notification_handler.js index bd408d429a4..d095e8aa7f4 100644 --- a/addons/website_livechat/static/src/core/website_livechat_notification_handler.js +++ b/addons/website_livechat/static/src/core/website_livechat_notification_handler.js @@ -3,23 +3,19 @@ import { registry } from "@web/core/registry"; export const websiteLivechatNotifications = { - dependencies: ["bus_service", "mail.chat_window", "mail.thread"], + dependencies: ["bus_service", "mail.chat_window", "mail.store"], start( env, - { - bus_service: busService, - "mail.chat_window": chatWindowService, - "mail.thread": threadService, - } + { bus_service: busService, "mail.chat_window": chatWindowService, "mail.store": store } ) { busService.subscribe("website_livechat.send_chat_request", (payload) => { - const channel = threadService.insert({ + const channel = store.Thread.insert({ ...payload, id: payload.id, model: "discuss.channel", type: payload.channel.channel_type, }); - const chatWindow = chatWindowService.insert({ thread: channel }); + const chatWindow = store.ChatWindow.insert({ thread: channel }); chatWindowService.makeVisible(chatWindow); chatWindowService.focus(chatWindow); });