diff --git a/addons/im_livechat/static/src/core/thread_model_patch.js b/addons/im_livechat/static/src/core/thread_model_patch.js index 685040ef0d9..cd79dff07ea 100644 --- a/addons/im_livechat/static/src/core/thread_model_patch.js +++ b/addons/im_livechat/static/src/core/thread_model_patch.js @@ -40,9 +40,7 @@ patch(Thread.prototype, { // For livechat threads, the correspondent is the first // channel member that is not the operator. const orderedChannelMembers = [...this.channelMembers].sort((a, b) => a.id - b.id); - const isFirstMemberOperator = - orderedChannelMembers[0]?.persona.type === "partner" && - orderedChannelMembers[0]?.persona.id === this.operator.id; + const isFirstMemberOperator = orderedChannelMembers[0]?.persona.eq(this.operator); correspondent = isFirstMemberOperator ? orderedChannelMembers[1]?.persona : orderedChannelMembers[0]?.persona; 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 00cc10f6968..4c220049d5a 100644 --- a/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js +++ b/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js @@ -261,7 +261,7 @@ export class ChatBotService { channel_uuid: this.livechatService.thread.uuid, }); this.currentStep.isEmailValid = success; - if (msg && !this.livechatService.thread.hasMessage(msg)) { + 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) }) ); diff --git a/addons/im_livechat/static/src/embed/core/autopopup_service.js b/addons/im_livechat/static/src/embed/core/autopopup_service.js index cc1a1f3fe0c..b3a7c2d4d19 100644 --- a/addons/im_livechat/static/src/embed/core/autopopup_service.js +++ b/addons/im_livechat/static/src/embed/core/autopopup_service.js @@ -58,9 +58,7 @@ export class AutopopupService { */ async shouldOpenChatWindow() { const thread = await this.threadService.getLivechatThread(); - return this.storeService.chatWindows.every( - (chatWindow) => chatWindow.thread.localId !== thread?.localId - ); + return this.storeService.chatWindows.every((cw) => !cw.thread?.eq(thread)); } get allowAutoPopup() { diff --git a/addons/mail/static/src/core/common/attachment_model.js b/addons/mail/static/src/core/common/attachment_model.js index 66554a80bab..42979862553 100644 --- a/addons/mail/static/src/core/common/attachment_model.js +++ b/addons/mail/static/src/core/common/attachment_model.js @@ -1,10 +1,11 @@ /* @odoo-module */ +import { Record } from "@mail/core/common/record"; import { assignDefined } from "@mail/utils/common/misc"; import { url } from "@web/core/utils/urls"; -export class Attachment { +export class Attachment extends Record { /** @type {import("@mail/core/common/store_service").Store} */ _store; accessToken; diff --git a/addons/mail/static/src/core/common/attachment_service.js b/addons/mail/static/src/core/common/attachment_service.js index e1168d57889..031d06b4544 100644 --- a/addons/mail/static/src/core/common/attachment_service.js +++ b/addons/mail/static/src/core/common/attachment_service.js @@ -63,7 +63,7 @@ export class AttachmentService { }); attachment.originThreadLocalId = createLocalId(threadData.model, threadData.id); const thread = attachment.originThread; - if (!thread.attachments.includes(attachment)) { + if (attachment.notIn(thread.attachments)) { thread.attachments.push(attachment); thread.attachments.sort((a1, a2) => (a1.id < a2.id ? 1 : -1)); } @@ -81,25 +81,20 @@ export class AttachmentService { } delete this.store.attachments[attachment.id]; if (attachment.originThread) { - removeFromArrayWithPredicate( - attachment.originThread.attachments, - ({ id }) => id === attachment.id + removeFromArrayWithPredicate(attachment.originThread.attachments, (att) => + att.eq(attachment) ); } for (const message of Object.values(this.store.messages)) { - removeFromArrayWithPredicate(message.attachments, ({ id }) => id === attachment.id); + removeFromArrayWithPredicate(message.attachments, (att) => att.eq(attachment)); if (message.composer) { - removeFromArrayWithPredicate( - message.composer.attachments, - ({ id }) => id === attachment.id + removeFromArrayWithPredicate(message.composer.attachments, (att) => + att.eq(attachment) ); } } for (const thread of Object.values(this.store.threads)) { - removeFromArrayWithPredicate( - thread.composer.attachments, - ({ id }) => id === attachment.id - ); + removeFromArrayWithPredicate(thread.composer.attachments, (att) => att.eq(attachment)); } } diff --git a/addons/mail/static/src/core/common/attachment_view.js b/addons/mail/static/src/core/common/attachment_view.js index 2e77c16eb0b..d04e87d941b 100644 --- a/addons/mail/static/src/core/common/attachment_view.js +++ b/addons/mail/static/src/core/common/attachment_view.js @@ -33,8 +33,8 @@ export class AttachmentView extends Component { } onClickNext() { - const index = this.state.thread.attachmentsInWebClientView.findIndex( - (attachment) => attachment.id === this.state.thread.mainAttachment.id + const index = this.state.thread.attachmentsInWebClientView.findIndex((attachment) => + attachment.eq(this.state.thread.mainAttachment) ); this.threadService.setMainAttachmentFromIndex( this.state.thread, @@ -43,8 +43,8 @@ export class AttachmentView extends Component { } onClickPrevious() { - const index = this.state.thread.attachmentsInWebClientView.findIndex( - (attachment) => attachment.id === this.state.thread.mainAttachment.id + const index = this.state.thread.attachmentsInWebClientView.findIndex((attachment) => + attachment.eq(this.state.thread.mainAttachment) ); this.threadService.setMainAttachmentFromIndex( this.state.thread, diff --git a/addons/mail/static/src/core/common/canned_response_model.js b/addons/mail/static/src/core/common/canned_response_model.js index 18dae3476b4..620b33bf620 100644 --- a/addons/mail/static/src/core/common/canned_response_model.js +++ b/addons/mail/static/src/core/common/canned_response_model.js @@ -1,6 +1,8 @@ /* @odoo-module */ -export class CannedResponse { +import { Record } from "@mail/core/common/record"; + +export class CannedResponse extends Record { /** @type {number} */ id; /** @type {string} */ diff --git a/addons/mail/static/src/core/common/channel_member_model.js b/addons/mail/static/src/core/common/channel_member_model.js index 2fcdcb6992f..7876d58a148 100644 --- a/addons/mail/static/src/core/common/channel_member_model.js +++ b/addons/mail/static/src/core/common/channel_member_model.js @@ -1,5 +1,6 @@ /* @odoo-module */ +import { Record } from "@mail/core/common/record"; import { createLocalId } from "@mail/utils/common/misc"; /** @@ -9,7 +10,7 @@ import { createLocalId } from "@mail/utils/common/misc"; * @property {string} personaLocalId * @property {number} threadId */ -export class ChannelMember { +export class ChannelMember extends Record { /** @type {number} */ id; personaLocalId; 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 2dddf0e91f6..b4b50a507ad 100644 --- a/addons/mail/static/src/core/common/channel_member_service.js +++ b/addons/mail/static/src/core/common/channel_member_service.js @@ -54,7 +54,7 @@ export class ChannelMemberService { switch (command) { case "insert": { - if (member.thread && !member.thread.channelMembers.includes(member)) { + if (member.thread && member.notIn(member.thread.channelMembers)) { member.thread.channelMembers.push(member); } } diff --git a/addons/mail/static/src/core/common/chat_window.js b/addons/mail/static/src/core/common/chat_window.js index 1047d5e1924..a56d1cd865c 100644 --- a/addons/mail/static/src/core/common/chat_window.js +++ b/addons/mail/static/src/core/common/chat_window.js @@ -103,8 +103,8 @@ export class ChatWindow extends Component { this.close({ escape: true }); break; case "Tab": { - const index = this.chatWindowService.visible.findIndex( - (cw) => cw === this.props.chatWindow + const index = this.chatWindowService.visible.findIndex((cw) => + cw.eq(this.props.chatWindow) ); if (index === 0) { this.chatWindowService.visible[this.chatWindowService.visible.length - 1] 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 7ca89453f4d..c69fafbed03 100644 --- a/addons/mail/static/src/core/common/chat_window_model.js +++ b/addons/mail/static/src/core/common/chat_window_model.js @@ -1,10 +1,12 @@ /* @odoo-module */ +import { Record } from "@mail/core/common/record"; + import { _t } from "@web/core/l10n/translation"; /** @typedef {{ thread?: import("@mail/core/common/thread_model").Thread, folded?: boolean, replaceNewMessageChatWindow?: boolean }} ChatWindowData */ -export class ChatWindow { +export class ChatWindow extends Record { /** @type {import("@mail/core/common/store_service").Store} */ _store; @@ -20,6 +22,7 @@ export class ChatWindow { * @returns {ChatWindow} */ constructor(store, data) { + super(); Object.assign(this, { thread: data.thread, _store: store, 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 9dfa6acfd30..6fca4a347c9 100644 --- a/addons/mail/static/src/core/common/chat_window_service.js +++ b/addons/mail/static/src/core/common/chat_window_service.js @@ -158,7 +158,7 @@ export class ChatWindowService { swaped.hidden = false; swaped.folded = false; } - const index = this.store.chatWindows.findIndex((c) => c === chatWindow); + const index = this.store.chatWindows.findIndex((c) => c.eq(chatWindow)); if (index > -1) { this.store.chatWindows.splice(index, 1); } diff --git a/addons/mail/static/src/core/common/composer.js b/addons/mail/static/src/core/common/composer.js index 1814efbedcc..1d8052580ad 100644 --- a/addons/mail/static/src/core/common/composer.js +++ b/addons/mail/static/src/core/common/composer.js @@ -175,7 +175,7 @@ export class Composer extends Component { ); useEffect( (rThread, cThread) => { - if (cThread && rThread === cThread) { + if (cThread && cThread.eq(rThread)) { this.state.autofocus++; } }, diff --git a/addons/mail/static/src/core/common/composer.xml b/addons/mail/static/src/core/common/composer.xml index 613dc8d87db..6cd10748eca 100644 --- a/addons/mail/static/src/core/common/composer.xml +++ b/addons/mail/static/src/core/common/composer.xml @@ -17,11 +17,11 @@
-