diff --git a/addons/mail/static/src/core/common/chat_window_model.js b/addons/mail/static/src/core/common/chat_window_model.js index 0f130b38119..cda6f344ecb 100644 --- a/addons/mail/static/src/core/common/chat_window_model.js +++ b/addons/mail/static/src/core/common/chat_window_model.js @@ -17,7 +17,11 @@ export class ChatWindow extends Record { static insert(data = {}) { const chatWindow = this.records.find((c) => c.threadLocalId === data.thread?.localId); if (!chatWindow) { - const chatWindow = new ChatWindow(this.store, data); + const chatWindow = new ChatWindow(); + Object.assign(chatWindow, { + thread: data.thread, + _store: this.store, + }); assignDefined(chatWindow, data); let index; const visible = this.env.services["mail.chat_window"].visible; @@ -56,19 +60,6 @@ export class ChatWindow extends Record { folded = false; hidden = false; - /** - * @param {import("@mail/core/common/store_service").Store} store - * @param {ChatWindowData} data - * @returns {ChatWindow} - */ - constructor(store, data) { - super(); - Object.assign(this, { - thread: data.thread, - _store: store, - }); - } - get thread() { return this._store.Thread.records[this.threadLocalId]; } diff --git a/addons/mail/static/src/core/common/composer_model.js b/addons/mail/static/src/core/common/composer_model.js index bf061b1f998..de4114a0f32 100644 --- a/addons/mail/static/src/core/common/composer_model.js +++ b/addons/mail/static/src/core/common/composer_model.js @@ -18,7 +18,20 @@ export class Composer extends Record { } let composer = (thread ?? message)?.composer; if (!composer) { - composer = new Composer(this.store, data); + composer = new Composer(); + const { message, thread } = data; + if (thread) { + composer.thread = thread; + Object.assign(composer, { thread }); + Object.assign(thread, { composer }); + } else if (message) { + Object.assign(composer, { message }); + Object.assign(message, { composer }); + } + Object.assign(composer, { + textInputContent: "", + _store: this.store, + }); } if ("textInputContent" in data) { composer.textInputContent = data.textInputContent; @@ -62,22 +75,6 @@ export class Composer extends Record { /** @type {import("@mail/core/common/store_service").Store} */ _store; isFocused = false; - - constructor(store, data) { - super(); - const { message, thread } = data; - if (thread) { - this.thread = thread; - thread.composer = this; - } else if (message) { - this.message = message; - message.composer = this; - } - Object.assign(this, { - textInputContent: "", - _store: store, - }); - } } modelRegistry.add(Composer.name, Composer); diff --git a/addons/mail/static/src/core/common/link_preview_model.js b/addons/mail/static/src/core/common/link_preview_model.js index fca2711a15f..44885e2c1fd 100644 --- a/addons/mail/static/src/core/common/link_preview_model.js +++ b/addons/mail/static/src/core/common/link_preview_model.js @@ -8,13 +8,14 @@ export class LinkPreview extends Record { * @returns {LinkPreview} */ static insert(data) { - const linkPreview = data.message.linkPreviews.find( - (linkPreview) => linkPreview.id === data.id - ); + let linkPreview = data.message.linkPreviews.find((lp) => lp.id === data.id); if (linkPreview) { return Object.assign(linkPreview, data); } - return new LinkPreview(data); + linkPreview = new LinkPreview(); + Object.assign(linkPreview, data); + this.store.Message.records[data.message.id]?.linkPreviews.push(linkPreview); + return linkPreview; } /** @type {number} */ @@ -36,15 +37,6 @@ export class LinkPreview extends Record { /** @type {string} */ source_url; - /** - * @param {Object} data - * @returns {LinkPreview} - */ - constructor(data) { - super(); - Object.assign(this, data); - } - get imageUrl() { return this.og_image ? this.og_image : this.source_url; } 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 a4748d32f65..6609961bf52 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 @@ -1,6 +1,5 @@ /* @odoo-module */ -import { LinkPreview } from "@mail/core/common/link_preview_model"; import { removeFromArrayWithPredicate } from "@mail/utils/common/arrays"; import { markup, reactive } from "@odoo/owl"; diff --git a/addons/mail/static/src/core/common/notification_group_model.js b/addons/mail/static/src/core/common/notification_group_model.js index 07c7513a458..6429874208b 100644 --- a/addons/mail/static/src/core/common/notification_group_model.js +++ b/addons/mail/static/src/core/common/notification_group_model.js @@ -22,7 +22,12 @@ export class NotificationGroup extends Record { ); }); if (!group) { - group = new NotificationGroup(this.store); + group = new NotificationGroup(); + group._store = this.store; + this.store.NotificationGroup.records.push(group); + group.id = nextId++; + // return reactive + group = this.store.NotificationGroup.records.find((g) => g.eq(group)); } this.env.services["mail.message"].updateNotificationGroup(group, data); if (group.notifications.length === 0) { @@ -46,15 +51,6 @@ export class NotificationGroup extends Record { /** @type {import("@mail/core/common/store_service").Store} */ _store; - constructor(store) { - super(); - this._store = store; - this._store.NotificationGroup.records.push(this); - this.id = nextId++; - // return reactive - return store.NotificationGroup.records.find((group) => group.eq(this)); - } - get iconSrc() { return "/mail/static/src/img/smiley/mailfailure.jpg"; } diff --git a/addons/mail/static/src/core/common/notification_model.js b/addons/mail/static/src/core/common/notification_model.js index 21af43a677b..a23dc27512d 100644 --- a/addons/mail/static/src/core/common/notification_model.js +++ b/addons/mail/static/src/core/common/notification_model.js @@ -14,7 +14,12 @@ export class Notification extends Record { static insert(data) { let notification = this.records[data.id]; if (!notification) { - this.records[data.id] = new Notification(this.store, data); + notification = new Notification(); + this.records[data.id] = notification; + Object.assign(notification, { + id: data.id, + _store: this.store, + }); notification = this.records[data.id]; } this.env.services["mail.message"].updateNotification(notification, data); @@ -36,14 +41,6 @@ export class Notification extends Record { /** @type {import("@mail/core/common/store_service").Store} */ _store; - constructor(store, data) { - super(); - Object.assign(this, { - id: data.id, - _store: store, - }); - } - get message() { return this._store.Message.records[this.messageId]; } diff --git a/addons/mail/static/src/core/common/scroll_position.js b/addons/mail/static/src/core/common/scroll_position.js index af6546af3f4..4f2db52c6f4 100644 --- a/addons/mail/static/src/core/common/scroll_position.js +++ b/addons/mail/static/src/core/common/scroll_position.js @@ -6,11 +6,6 @@ export class ScrollPosition { /** @type {number|undefined} */ left; - constructor(top, left) { - this.top = top; - this.left = left; - } - clear() { this.top = this.left = undefined; } diff --git a/addons/mail/static/src/core/common/thread_model.js b/addons/mail/static/src/core/common/thread_model.js index 9de43fa6f81..27fc8d5b947 100644 --- a/addons/mail/static/src/core/common/thread_model.js +++ b/addons/mail/static/src/core/common/thread_model.js @@ -41,7 +41,16 @@ export class Thread extends Record { this.env.services["mail.thread"].update(thread, data); return thread; } - const thread = new Thread(this.store, data); + let thread = new Thread(); + Object.assign(thread, { + id: data.id, + model: data.model, + type: data.type, + _store: this.store, + }); + this.records[thread.localId] = thread; + // return reactive version. + thread = this.records[thread.localId]; onChange(thread, "message_unread_counter", () => { if (thread.channel) { thread.channel.message_unread_counter = thread.message_unread_counter; @@ -57,7 +66,7 @@ export class Thread extends Record { this.env.services["mail.thread"].update(thread, data); this.store.Composer.insert({ thread }); // return reactive version. - return this.records[thread.localId]; + return thread; } /** @type {number} */ @@ -173,18 +182,6 @@ export class Thread extends Record { /** @type {Boolean} */ is_editable; - constructor(store, data) { - super(); - Object.assign(this, { - id: data.id, - model: data.model, - type: data.type, - _store: store, - }); - store.Thread.records[this.localId] = this; - return store.Thread.records[this.localId]; - } - get accessRestrictedToGroupText() { if (!this.authorizedGroupFullName) { return false; diff --git a/addons/mail/static/src/core/common/thread_service.js b/addons/mail/static/src/core/common/thread_service.js index 9ee5bf863dc..2303664b8c4 100644 --- a/addons/mail/static/src/core/common/thread_service.js +++ b/addons/mail/static/src/core/common/thread_service.js @@ -1,6 +1,5 @@ /* @odoo-module */ -import { Composer } from "@mail/core/common/composer_model"; import { loadEmoji } from "@web/core/emoji_picker/emoji_picker"; import { DEFAULT_AVATAR } from "@mail/core/common/persona_service"; import { diff --git a/addons/mail/static/src/core/web/activity_model.js b/addons/mail/static/src/core/web/activity_model.js index 26897f517c2..54fa94b505f 100644 --- a/addons/mail/static/src/core/web/activity_model.js +++ b/addons/mail/static/src/core/web/activity_model.js @@ -44,7 +44,17 @@ export class Activity extends Record { * @returns {Activity} */ static insert(data, { broadcast = true } = {}) { - const activity = this.records[data.id] ?? new Activity(this.store, data.id); + let activity = this.records[data.id]; + if (!activity) { + activity = new Activity(); + Object.assign(activity, { + id: data.id, + _store: this.store, + }); + this.store.Activity.records[data.id] = activity; + // return reactive + activity = this.store.Activity.records[data.id]; + } if (data.request_partner_id) { data.request_partner_id = data.request_partner_id[0]; } @@ -114,21 +124,6 @@ export class Activity extends Record { write_uid; /** @type {import("@mail/core/common/store_service").Store} */ _store; - - /** - * @param {import("@mail/core/common/store_service").Store} store - * @param {number} id - * @returns {Activity} - */ - constructor(store, id) { - super(); - Object.assign(this, { - id, - _store: store, - }); - store.Activity.records[id] = this; - return store.Activity.records[id]; - } } modelRegistry.add(Activity.name, Activity);