From c6216f08329dade83c86b9715700e0d1bcb96578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 18 Aug 2021 20:13:15 +0000 Subject: [PATCH] [IMP] mail, *: access models without env in components * = im_livechat, snailmail, website_livechat And finally remove env.models as this was the last remaining usage. Part of task-2582313 --- .../components/discuss_sidebar/discuss_sidebar.js | 2 +- .../notification_list/notification_list.js | 2 +- .../use_component_to_model.js | 9 +++++---- .../use_ref_to_model/use_ref_to_model.js | 9 +++++---- .../use_update_to_model/use_update_to_model.js | 2 +- .../static/src/components/activity/activity.js | 2 +- .../components/activity/tests/activity_tests.js | 2 +- .../src/components/activity_box/activity_box.js | 2 +- .../activity_mark_done_popover.js | 2 +- .../src/components/attachment/attachment.js | 6 +++--- .../components/attachment_box/attachment_box.js | 2 +- .../attachment_delete_confirm_dialog.js | 2 +- .../components/attachment_list/attachment_list.js | 2 +- .../attachment_viewer/attachment_viewer.js | 2 +- .../channel_invitation_form.js | 2 +- .../src/components/chat_window/chat_window.js | 4 ++-- .../chat_window_header/chat_window_header.js | 2 +- .../chat_window_hidden_menu.js | 3 +++ .../mail/static/src/components/chatter/chatter.js | 2 +- .../components/chatter_topbar/chatter_topbar.js | 2 +- .../static/src/components/composer/composer.js | 2 +- .../composer_suggested_recipient.js | 2 +- .../composer_suggested_recipient_list.js | 2 +- .../composer_suggestion/composer_suggestion.js | 4 ++-- .../composer_suggestion_list.js | 2 +- .../composer_text_input/composer_text_input.js | 2 +- .../mail/static/src/components/dialog/dialog.js | 2 +- .../mail/static/src/components/discuss/discuss.js | 6 ++++++ .../src/components/discuss/tests/discuss_tests.js | 12 ++++++++++++ .../discuss_mobile_mailbox_selection.js | 7 +++++-- .../components/discuss_sidebar/discuss_sidebar.js | 6 +++--- .../discuss_sidebar/discuss_sidebar.xml | 2 +- .../discuss_sidebar_item/discuss_sidebar_item.js | 2 +- .../src/components/file_uploader/file_uploader.js | 12 ++++++------ .../src/components/follow_button/follow_button.js | 2 +- .../static/src/components/follower/follower.js | 2 +- .../follower_list_menu/follower_list_menu.js | 2 +- .../follower_subtype/follower_subtype.js | 4 ++-- .../follower_subtype_list.js | 2 +- .../src/components/mail_template/mail_template.js | 4 ++-- .../mail/static/src/components/message/message.js | 4 ++-- .../message_author_prefix.js | 4 ++-- .../src/components/message_list/message_list.js | 4 ++-- .../message_seen_indicator.js | 6 +++--- .../components/messaging_menu/messaging_menu.js | 2 +- .../notification_group/notification_group.js | 2 +- .../notification_list/notification_list.js | 15 +++++++++------ .../notification_popover/notification_popover.js | 5 ++++- .../partner_im_status_icon.js | 2 +- .../src/components/thread_icon/thread_icon.js | 2 +- .../thread_needaction_preview.js | 4 ++-- .../components/thread_preview/thread_preview.js | 2 +- .../thread_textual_typing_status.js | 2 +- .../src/components/thread_view/thread_view.js | 2 +- .../thread_view_topbar/thread_view_topbar.js | 2 +- addons/mail/static/src/main.js | 5 ----- .../mail/static/src/utils/messaging_component.js | 7 +++++-- addons/mail/static/src/utils/test_utils.js | 5 ----- .../snailmail_error_dialog.js | 2 +- .../snailmail_notification_popover.js | 2 +- .../components/visitor_banner/visitor_banner.js | 2 +- 61 files changed, 123 insertions(+), 98 deletions(-) diff --git a/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.js b/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.js index d12c00892e4..20ca571ab60 100644 --- a/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.js +++ b/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.js @@ -18,7 +18,7 @@ patch(components.DiscussSidebar.prototype, 'im_livechat/static/src/components/di * @returns {mail.thread[]} */ quickSearchOrderedAndPinnedLivechatList() { - const allOrderedAndPinnedLivechats = this.env.models['mail.thread'] + const allOrderedAndPinnedLivechats = this.messaging.models['mail.thread'] .all(thread => thread.channel_type === 'livechat' && thread.isPinned && diff --git a/addons/im_livechat/static/src/components/notification_list/notification_list.js b/addons/im_livechat/static/src/components/notification_list/notification_list.js index ad6fa3496ab..dd8fcc36911 100644 --- a/addons/im_livechat/static/src/components/notification_list/notification_list.js +++ b/addons/im_livechat/static/src/components/notification_list/notification_list.js @@ -20,7 +20,7 @@ patch(components.NotificationList.prototype, 'im_livechat/static/src/components/ */ _getThreads(props) { if (props.filter === 'livechat') { - return this.env.models['mail.thread'].all(thread => + return this.messaging.models['mail.thread'].all(thread => thread.channel_type === 'livechat' && thread.isPinned && thread.model === 'mail.channel' diff --git a/addons/mail/static/src/component_hooks/use_component_to_model/use_component_to_model.js b/addons/mail/static/src/component_hooks/use_component_to_model/use_component_to_model.js index a31c95903a3..36ae5fec42b 100644 --- a/addons/mail/static/src/component_hooks/use_component_to_model/use_component_to_model.js +++ b/addons/mail/static/src/component_hooks/use_component_to_model/use_component_to_model.js @@ -17,23 +17,24 @@ const { onWillUpdateProps, useComponent } = owl.hooks; */ export function useComponentToModel({ fieldName, modelName, propNameAsRecordLocalId }) { const component = useComponent(); - const record = component.env.models[modelName].get(component.props[propNameAsRecordLocalId]); + const { modelManager } = component.env.services.messaging; + const record = modelManager.models[modelName].get(component.props[propNameAsRecordLocalId]); if (record) { record.update({ [fieldName]: component }); } onWillUpdateProps(nextProps => { - const currentRecord = component.env.models[modelName].get(component.props[propNameAsRecordLocalId]); + const currentRecord = modelManager.models[modelName].get(component.props[propNameAsRecordLocalId]); if (currentRecord) { currentRecord.update({ [fieldName]: clear() }); } - const nextRecord = component.env.models[modelName].get(nextProps[propNameAsRecordLocalId]); + const nextRecord = modelManager.models[modelName].get(nextProps[propNameAsRecordLocalId]); if (nextRecord) { nextRecord.update({ [fieldName]: component }); } }); const __destroy = component.__destroy; component.__destroy = parent => { - const record = component.env.models[modelName].get(component.props[propNameAsRecordLocalId]); + const record = modelManager.models[modelName].get(component.props[propNameAsRecordLocalId]); if (record) { record.update({ [fieldName]: clear() }); } diff --git a/addons/mail/static/src/component_hooks/use_ref_to_model/use_ref_to_model.js b/addons/mail/static/src/component_hooks/use_ref_to_model/use_ref_to_model.js index 7c5ab390dcc..439910e919d 100644 --- a/addons/mail/static/src/component_hooks/use_ref_to_model/use_ref_to_model.js +++ b/addons/mail/static/src/component_hooks/use_ref_to_model/use_ref_to_model.js @@ -18,24 +18,25 @@ const { onWillUpdateProps, useComponent, useRef } = owl.hooks; */ export function useRefToModel({ fieldName, modelName, propNameAsRecordLocalId, refName }) { const component = useComponent(); - const record = component.env.models[modelName].get(component.props[propNameAsRecordLocalId]); + const { modelManager } = component.env.services.messaging; + const record = modelManager.models[modelName].get(component.props[propNameAsRecordLocalId]); const ref = useRef(refName); if (record) { record.update({ [fieldName]: ref }); } onWillUpdateProps(nextProps => { - const currentRecord = component.env.models[modelName].get(component.props[propNameAsRecordLocalId]); + const currentRecord = modelManager.models[modelName].get(component.props[propNameAsRecordLocalId]); if (currentRecord) { currentRecord.update({ [fieldName]: clear() }); } - const nextRecord = component.env.models[modelName].get(nextProps[propNameAsRecordLocalId]); + const nextRecord = modelManager.models[modelName].get(nextProps[propNameAsRecordLocalId]); if (nextRecord) { nextRecord.update({ [fieldName]: ref }); } }); const __destroy = component.__destroy; component.__destroy = parent => { - const record = component.env.models[modelName].get(component.props[propNameAsRecordLocalId]); + const record = modelManager.models[modelName].get(component.props[propNameAsRecordLocalId]); if (record) { record.update({ [fieldName]: clear() }); } diff --git a/addons/mail/static/src/component_hooks/use_update_to_model/use_update_to_model.js b/addons/mail/static/src/component_hooks/use_update_to_model/use_update_to_model.js index 1e411ed12a9..f9521474ec6 100644 --- a/addons/mail/static/src/component_hooks/use_update_to_model/use_update_to_model.js +++ b/addons/mail/static/src/component_hooks/use_update_to_model/use_update_to_model.js @@ -17,7 +17,7 @@ const { useComponent } = owl.hooks; export function useUpdateToModel({ methodName, modelName, propNameAsRecordLocalId }) { const component = useComponent(); useUpdate({ func: () => { - const record = component.env.models[modelName].get(component.props[propNameAsRecordLocalId]); + const record = component.env.services.messaging.modelManager.models[modelName].get(component.props[propNameAsRecordLocalId]); if (record) { record[methodName](); } diff --git a/addons/mail/static/src/components/activity/activity.js b/addons/mail/static/src/components/activity/activity.js index 3f701d1f4f6..dcf4fa321be 100644 --- a/addons/mail/static/src/components/activity/activity.js +++ b/addons/mail/static/src/components/activity/activity.js @@ -36,7 +36,7 @@ export class Activity extends Component { * @returns {mail.activity} */ get activity() { - return this.env.models['mail.activity'].get(this.props.activityLocalId); + return this.messaging && this.messaging.models['mail.activity'].get(this.props.activityLocalId); } /** diff --git a/addons/mail/static/src/components/activity/tests/activity_tests.js b/addons/mail/static/src/components/activity/tests/activity_tests.js index 0b1ef7adffd..caea8456c28 100644 --- a/addons/mail/static/src/components/activity/tests/activity_tests.js +++ b/addons/mail/static/src/components/activity/tests/activity_tests.js @@ -975,7 +975,7 @@ QUnit.test('activity click on cancel', async function (assert) { * @returns {mail.activity} */ get activity() { - return this.env.models['mail.activity'].get(this.props.activityLocalId); + return this.messaging.models['mail.activity'].get(this.props.activityLocalId); } } ParentComponent.env = this.env; diff --git a/addons/mail/static/src/components/activity_box/activity_box.js b/addons/mail/static/src/components/activity_box/activity_box.js index e570202d9cb..e053423387b 100644 --- a/addons/mail/static/src/components/activity_box/activity_box.js +++ b/addons/mail/static/src/components/activity_box/activity_box.js @@ -14,7 +14,7 @@ export class ActivityBox extends Component { * @returns {Chatter} */ get chatter() { - return this.env.models['mail.chatter'].get(this.props.chatterLocalId); + return this.messaging.models['mail.chatter'].get(this.props.chatterLocalId); } } diff --git a/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover.js b/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover.js index e306159b43f..21bc13b79b1 100644 --- a/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover.js +++ b/addons/mail/static/src/components/activity_mark_done_popover/activity_mark_done_popover.js @@ -30,7 +30,7 @@ export class ActivityMarkDonePopover extends Component { * @returns {mail.activity} */ get activity() { - return this.env.models['mail.activity'].get(this.props.activityLocalId); + return this.messaging && this.messaging.models['mail.activity'].get(this.props.activityLocalId); } /** diff --git a/addons/mail/static/src/components/attachment/attachment.js b/addons/mail/static/src/components/attachment/attachment.js index 3ef672467f3..c37593973dd 100644 --- a/addons/mail/static/src/components/attachment/attachment.js +++ b/addons/mail/static/src/components/attachment/attachment.js @@ -24,7 +24,7 @@ export class Attachment extends Component { * @returns {mail.attachment} */ get attachment() { - return this.env.models['mail.attachment'].get(this.props.attachmentLocalId); + return this.messaging && this.messaging.models['mail.attachment'].get(this.props.attachmentLocalId); } /** @@ -115,10 +115,10 @@ export class Attachment extends Component { if (!this.attachment.isViewable) { return; } - this.env.models['mail.attachment'].view({ + this.messaging.models['mail.attachment'].view({ attachment: this.attachment, attachments: this.props.attachmentLocalIds.map( - attachmentLocalId => this.env.models['mail.attachment'].get(attachmentLocalId) + attachmentLocalId => this.messaging.models['mail.attachment'].get(attachmentLocalId) ), }); } diff --git a/addons/mail/static/src/components/attachment_box/attachment_box.js b/addons/mail/static/src/components/attachment_box/attachment_box.js index be9e74e6fa1..17d626ff9ee 100644 --- a/addons/mail/static/src/components/attachment_box/attachment_box.js +++ b/addons/mail/static/src/components/attachment_box/attachment_box.js @@ -42,7 +42,7 @@ export class AttachmentBox extends Component { * @returns {mail.thread|undefined} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js b/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js index 277b249bff5..d892416cd46 100644 --- a/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js +++ b/addons/mail/static/src/components/attachment_delete_confirm_dialog/attachment_delete_confirm_dialog.js @@ -26,7 +26,7 @@ export class AttachmentDeleteConfirmDialog extends Component { * @returns {mail.attachment} */ get attachment() { - return this.env.models['mail.attachment'].get(this.props.attachmentLocalId); + return this.messaging && this.messaging.models['mail.attachment'].get(this.props.attachmentLocalId); } /** diff --git a/addons/mail/static/src/components/attachment_list/attachment_list.js b/addons/mail/static/src/components/attachment_list/attachment_list.js index fc3a1ebcb13..b5405687c12 100644 --- a/addons/mail/static/src/components/attachment_list/attachment_list.js +++ b/addons/mail/static/src/components/attachment_list/attachment_list.js @@ -14,7 +14,7 @@ export class AttachmentList extends Component { * @returns {mail.attachment[]} */ get attachments() { - return this.env.models['mail.attachment'].all().filter(attachment => + return this.messaging && this.messaging.models['mail.attachment'].all().filter(attachment => this.props.attachmentLocalIds.includes(attachment.localId) ); } diff --git a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js index 87e44692022..a5178483663 100644 --- a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js +++ b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.js @@ -80,7 +80,7 @@ export class AttachmentViewer extends Component { * @returns {mail.attachment_viewer} */ get attachmentViewer() { - return this.env.models['mail.attachment_viewer'].get(this.props.localId); + return this.messaging && this.messaging.models['mail.attachment_viewer'].get(this.props.localId); } /** diff --git a/addons/mail/static/src/components/channel_invitation_form/channel_invitation_form.js b/addons/mail/static/src/components/channel_invitation_form/channel_invitation_form.js index fac83d8be71..ad984717884 100644 --- a/addons/mail/static/src/components/channel_invitation_form/channel_invitation_form.js +++ b/addons/mail/static/src/components/channel_invitation_form/channel_invitation_form.js @@ -24,7 +24,7 @@ export class ChannelInvitationForm extends Component { //-------------------------------------------------------------------------- get channelInvitationForm() { - return this.env.models['mail.channel_invitation_form'].get(this.props.localId); + return this.messaging && this.messaging.models['mail.channel_invitation_form'].get(this.props.localId); } } diff --git a/addons/mail/static/src/components/chat_window/chat_window.js b/addons/mail/static/src/components/chat_window/chat_window.js index 7f56e0e34f4..67753e14328 100644 --- a/addons/mail/static/src/components/chat_window/chat_window.js +++ b/addons/mail/static/src/components/chat_window/chat_window.js @@ -52,7 +52,7 @@ export class ChatWindow extends Component { * @returns {mail.chat_window} */ get chatWindow() { - return this.env.models['mail.chat_window'].get(this.props.chatWindowLocalId); + return this.messaging && this.messaging.models['mail.chat_window'].get(this.props.chatWindowLocalId); } /** @@ -181,7 +181,7 @@ export class ChatWindow extends Component { * @param {function} res */ _onAutocompleteSource(req, res) { - this.env.models['mail.partner'].imSearch({ + this.messaging.models['mail.partner'].imSearch({ callback: (partners) => { const suggestions = partners.map(partner => { return { diff --git a/addons/mail/static/src/components/chat_window_header/chat_window_header.js b/addons/mail/static/src/components/chat_window_header/chat_window_header.js index 49ce57afeb9..f8084386ed1 100644 --- a/addons/mail/static/src/components/chat_window_header/chat_window_header.js +++ b/addons/mail/static/src/components/chat_window_header/chat_window_header.js @@ -18,7 +18,7 @@ export class ChatWindowHeader extends Component { * @returns {mail.chat_window} */ get chatWindow() { - return this.env.models['mail.chat_window'].get(this.props.chatWindowLocalId); + return this.messaging && this.messaging.models['mail.chat_window'].get(this.props.chatWindowLocalId); } /** diff --git a/addons/mail/static/src/components/chat_window_hidden_menu/chat_window_hidden_menu.js b/addons/mail/static/src/components/chat_window_hidden_menu/chat_window_hidden_menu.js index dfa59601160..44ec50d5fde 100644 --- a/addons/mail/static/src/components/chat_window_hidden_menu/chat_window_hidden_menu.js +++ b/addons/mail/static/src/components/chat_window_hidden_menu/chat_window_hidden_menu.js @@ -45,6 +45,9 @@ export class ChatWindowHiddenMenu extends Component { * @private */ _apply() { + if (!this.messaging) { + return; + } this._applyListHeight(); this._applyOffset(); this._wasMenuOpen = this.env.messaging.chatWindowManager.isHiddenMenuOpen; diff --git a/addons/mail/static/src/components/chatter/chatter.js b/addons/mail/static/src/components/chatter/chatter.js index 3fa8307cf57..bafaee60a9a 100644 --- a/addons/mail/static/src/components/chatter/chatter.js +++ b/addons/mail/static/src/components/chatter/chatter.js @@ -38,7 +38,7 @@ export class Chatter extends Component { * @returns {mail.chatter} */ get chatter() { - return this.env.models['mail.chatter'].get(this.props.chatterLocalId); + return this.messaging && this.messaging.models['mail.chatter'].get(this.props.chatterLocalId); } /** diff --git a/addons/mail/static/src/components/chatter_topbar/chatter_topbar.js b/addons/mail/static/src/components/chatter_topbar/chatter_topbar.js index 069a8c4c2cb..0d70fd0c9f3 100644 --- a/addons/mail/static/src/components/chatter_topbar/chatter_topbar.js +++ b/addons/mail/static/src/components/chatter_topbar/chatter_topbar.js @@ -14,7 +14,7 @@ export class ChatterTopbar extends Component { * @returns {mail.chatter} */ get chatter() { - return this.env.models['mail.chatter'].get(this.props.chatterLocalId); + return this.messaging && this.messaging.models['mail.chatter'].get(this.props.chatterLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/composer/composer.js b/addons/mail/static/src/components/composer/composer.js index 9b854620b8b..df6c1d364af 100644 --- a/addons/mail/static/src/components/composer/composer.js +++ b/addons/mail/static/src/components/composer/composer.js @@ -54,7 +54,7 @@ export class Composer extends Component { * @returns {mail.composer} */ get composer() { - return this.env.models['mail.composer'].get(this.props.composerLocalId); + return this.messaging && this.messaging.models['mail.composer'].get(this.props.composerLocalId); } /** diff --git a/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js b/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js index 91e6c16506b..b2c8ad3182c 100644 --- a/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js +++ b/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js @@ -78,7 +78,7 @@ export class ComposerSuggestedRecipient extends Component { * @returns {mail.suggested_recipient_info} */ get suggestedRecipientInfo() { - return this.env.models['mail.suggested_recipient_info'].get(this.props.suggestedRecipientInfoLocalId); + return this.messaging && this.messaging.models['mail.suggested_recipient_info'].get(this.props.suggestedRecipientInfoLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/composer_suggested_recipient_list/composer_suggested_recipient_list.js b/addons/mail/static/src/components/composer_suggested_recipient_list/composer_suggested_recipient_list.js index b58c9c7f297..f8258eaa7aa 100644 --- a/addons/mail/static/src/components/composer_suggested_recipient_list/composer_suggested_recipient_list.js +++ b/addons/mail/static/src/components/composer_suggested_recipient_list/composer_suggested_recipient_list.js @@ -25,7 +25,7 @@ export class ComposerSuggestedRecipientList extends Component { * @returns {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/composer_suggestion/composer_suggestion.js b/addons/mail/static/src/components/composer_suggestion/composer_suggestion.js index b3bb9b7fa6f..1b1715f5fd5 100644 --- a/addons/mail/static/src/components/composer_suggestion/composer_suggestion.js +++ b/addons/mail/static/src/components/composer_suggestion/composer_suggestion.js @@ -24,7 +24,7 @@ export class ComposerSuggestion extends Component { * @returns {mail.composer} */ get composer() { - return this.env.models['mail.composer'].get(this.props.composerLocalId); + return this.messaging && this.messaging.models['mail.composer'].get(this.props.composerLocalId); } get isCannedResponse() { @@ -44,7 +44,7 @@ export class ComposerSuggestion extends Component { } get record() { - return this.env.models[this.props.modelName].get(this.props.recordLocalId); + return this.messaging && this.messaging.models[this.props.modelName].get(this.props.recordLocalId); } /** diff --git a/addons/mail/static/src/components/composer_suggestion_list/composer_suggestion_list.js b/addons/mail/static/src/components/composer_suggestion_list/composer_suggestion_list.js index 36ce83b5a55..8621ce65e51 100644 --- a/addons/mail/static/src/components/composer_suggestion_list/composer_suggestion_list.js +++ b/addons/mail/static/src/components/composer_suggestion_list/composer_suggestion_list.js @@ -14,7 +14,7 @@ export class ComposerSuggestionList extends Component { * @returns {mail.composer} */ get composer() { - return this.env.models['mail.composer'].get(this.props.composerLocalId); + return this.messaging && this.messaging.models['mail.composer'].get(this.props.composerLocalId); } } diff --git a/addons/mail/static/src/components/composer_text_input/composer_text_input.js b/addons/mail/static/src/components/composer_text_input/composer_text_input.js index 8b25f389e76..e9f4620b2c9 100644 --- a/addons/mail/static/src/components/composer_text_input/composer_text_input.js +++ b/addons/mail/static/src/components/composer_text_input/composer_text_input.js @@ -44,7 +44,7 @@ export class ComposerTextInput extends Component { * @returns {mail.composer} */ get composer() { - return this.env.models['mail.composer'].get(this.props.composerLocalId); + return this.messaging && this.messaging.models['mail.composer'].get(this.props.composerLocalId); } /** diff --git a/addons/mail/static/src/components/dialog/dialog.js b/addons/mail/static/src/components/dialog/dialog.js index a4e5bca5246..bcc0331b905 100644 --- a/addons/mail/static/src/components/dialog/dialog.js +++ b/addons/mail/static/src/components/dialog/dialog.js @@ -44,7 +44,7 @@ export class Dialog extends Component { * @returns {mail.dialog} */ get dialog() { - return this.env.models['mail.dialog'].get(this.props.dialogLocalId); + return this.messaging && this.messaging.models['mail.dialog'].get(this.props.dialogLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/discuss/discuss.js b/addons/mail/static/src/components/discuss/discuss.js index e80fde04eee..df879716f4f 100644 --- a/addons/mail/static/src/components/discuss/discuss.js +++ b/addons/mail/static/src/components/discuss/discuss.js @@ -27,6 +27,9 @@ export class Discuss extends Component { } mounted() { + if (!this.discuss) { + return; + } this.discuss.update({ isOpen: true }); if (this.discuss.thread) { this.trigger('o-push-state-action-manager'); @@ -114,6 +117,9 @@ export class Discuss extends Component { * @private */ _updateLocalStoreProps() { + if (!this.discuss) { + return; + } /** * Locally tracked store props `activeThreadCache`. * Useful to set scroll position from last stored one and to display diff --git a/addons/mail/static/src/components/discuss/tests/discuss_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_tests.js index 23a5ea95b94..99fd938b506 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js @@ -38,6 +38,18 @@ QUnit.module('discuss_tests.js', { }, }); +QUnit.test('messaging not created', async function (assert) { + assert.expect(1); + + const messagingBeforeCreationDeferred = makeTestPromise(); + await this.start({ + messagingBeforeCreationDeferred, + waitUntilMessagingCondition: 'none' + }); + assert.containsOnce(document.body, '.o_Discuss_messagingNotInitialized', "should display messaging not initialized"); + messagingBeforeCreationDeferred.resolve(); +}); + QUnit.test('messaging not initialized', async function (assert) { assert.expect(1); diff --git a/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection.js b/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection.js index fcd10df9cdc..b37b5c4bd70 100644 --- a/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection.js +++ b/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection.js @@ -14,7 +14,10 @@ export class DiscussMobileMailboxSelection extends Component { * @returns {mail.thread[]} */ get orderedMailboxes() { - return this.env.models['mail.thread'] + if (!this.messaging) { + return []; + } + return this.messaging.models['mail.thread'] .all(thread => thread.isPinned && thread.model === 'mail.box') .sort((mailbox1, mailbox2) => { if (mailbox1 === this.discuss.messaging.inbox) { @@ -54,7 +57,7 @@ export class DiscussMobileMailboxSelection extends Component { */ _onClick(ev) { const { mailboxLocalId } = ev.currentTarget.dataset; - const mailbox = this.env.models['mail.thread'].get(mailboxLocalId); + const mailbox = this.messaging.models['mail.thread'].get(mailboxLocalId); if (!mailbox) { return; } diff --git a/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.js b/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.js index ac6785e1cef..4a5b3a445a8 100644 --- a/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.js +++ b/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.js @@ -49,7 +49,7 @@ export class DiscussSidebar extends Component { * @returns {mail.thread[]} */ get orderedMailboxes() { - return this.env.models['mail.thread'] + return this.messaging.models['mail.thread'] .all(thread => thread.isPinned && thread.model === 'mail.box') .sort((mailbox1, mailbox2) => { if (mailbox1 === this.discuss.messaging.inbox) { @@ -76,7 +76,7 @@ export class DiscussSidebar extends Component { * @returns {mail.thread[]} */ get quickSearchPinnedAndOrderedChats() { - const allOrderedAndPinnedChats = this.env.models['mail.thread'] + const allOrderedAndPinnedChats = this.messaging.models['mail.thread'] .all(thread => thread.channel_type === 'chat' && thread.isPinned && @@ -99,7 +99,7 @@ export class DiscussSidebar extends Component { * @returns {mail.thread[]} */ get quickSearchOrderedAndPinnedMultiUserChannels() { - const allOrderedAndPinnedMultiUserChannels = this.env.models['mail.thread'] + const allOrderedAndPinnedMultiUserChannels = this.messaging.models['mail.thread'] .all(thread => thread.channel_type === 'channel' && thread.isPinned && diff --git a/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.xml b/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.xml index d0efa9bfdf8..0859456cc62 100644 --- a/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.xml +++ b/addons/mail/static/src/components/discuss_sidebar/discuss_sidebar.xml @@ -13,7 +13,7 @@
- +
diff --git a/addons/mail/static/src/components/discuss_sidebar_item/discuss_sidebar_item.js b/addons/mail/static/src/components/discuss_sidebar_item/discuss_sidebar_item.js index 1babc38c69b..fdae57414b8 100644 --- a/addons/mail/static/src/components/discuss_sidebar_item/discuss_sidebar_item.js +++ b/addons/mail/static/src/components/discuss_sidebar_item/discuss_sidebar_item.js @@ -47,7 +47,7 @@ export class DiscussSidebarItem extends Component { * @returns {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/file_uploader/file_uploader.js b/addons/mail/static/src/components/file_uploader/file_uploader.js index 7a0015ced0e..e22412b941e 100644 --- a/addons/mail/static/src/components/file_uploader/file_uploader.js +++ b/addons/mail/static/src/components/file_uploader/file_uploader.js @@ -57,7 +57,7 @@ export class FileUploader extends Component { * @returns {mail.attachment} */ _createAttachment(fileData) { - return this.env.models['mail.attachment'].create(Object.assign( + return this.messaging.models['mail.attachment'].create(Object.assign( {}, fileData, this.props.newAttachmentExtraData @@ -85,7 +85,7 @@ export class FileUploader extends Component { */ _createUploadingAttachments(files) { for (const file of files) { - this.env.models['mail.attachment'].create( + this.messaging.models['mail.attachment'].create( Object.assign( { filename: file.name, @@ -104,7 +104,7 @@ export class FileUploader extends Component { */ async _performUpload(files) { for (const file of files) { - const uploadingAttachment = this.env.models['mail.attachment'].find(attachment => + const uploadingAttachment = this.messaging.models['mail.attachment'].find(attachment => attachment.isUploading && attachment.filename === file.name ); @@ -139,7 +139,7 @@ export class FileUploader extends Component { async _unlinkExistingAttachments(files) { for (const file of files) { const attachment = this.props.attachmentLocalIds - .map(attachmentLocalId => this.env.models['mail.attachment'].get(attachmentLocalId)) + .map(attachmentLocalId => this.messaging.models['mail.attachment'].get(attachmentLocalId)) .find(attachment => attachment.name === file.name && attachment.size === file.size); // if the files already exits, delete the file before upload if (attachment) { @@ -165,7 +165,7 @@ export class FileUploader extends Component { type: 'danger', message: error, }); - const relatedUploadingAttachments = this.env.models['mail.attachment'] + const relatedUploadingAttachments = this.messaging.models['mail.attachment'] .find(attachment => attachment.filename === filename && attachment.isUploading @@ -175,7 +175,7 @@ export class FileUploader extends Component { } return; } - const attachment = this.env.models['mail.attachment'].insert( + const attachment = this.messaging.models['mail.attachment'].insert( Object.assign( { filename, diff --git a/addons/mail/static/src/components/follow_button/follow_button.js b/addons/mail/static/src/components/follow_button/follow_button.js index 07a397a04ea..5bf06412a13 100644 --- a/addons/mail/static/src/components/follow_button/follow_button.js +++ b/addons/mail/static/src/components/follow_button/follow_button.js @@ -27,7 +27,7 @@ export class FollowButton extends Component { * @return {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/follower/follower.js b/addons/mail/static/src/components/follower/follower.js index 44948477ff5..38db4604396 100644 --- a/addons/mail/static/src/components/follower/follower.js +++ b/addons/mail/static/src/components/follower/follower.js @@ -14,7 +14,7 @@ export class Follower extends Component { * @returns {mail.follower} */ get follower() { - return this.env.models['mail.follower'].get(this.props.followerLocalId); + return this.messaging && this.messaging.models['mail.follower'].get(this.props.followerLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/follower_list_menu/follower_list_menu.js b/addons/mail/static/src/components/follower_list_menu/follower_list_menu.js index 8f80d33324e..9fe2a146f93 100644 --- a/addons/mail/static/src/components/follower_list_menu/follower_list_menu.js +++ b/addons/mail/static/src/components/follower_list_menu/follower_list_menu.js @@ -37,7 +37,7 @@ export class FollowerListMenu extends Component { * @return {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/follower_subtype/follower_subtype.js b/addons/mail/static/src/components/follower_subtype/follower_subtype.js index 16b99ce8233..fb51d21753d 100644 --- a/addons/mail/static/src/components/follower_subtype/follower_subtype.js +++ b/addons/mail/static/src/components/follower_subtype/follower_subtype.js @@ -14,14 +14,14 @@ export class FollowerSubtype extends Component { * @returns {mail.follower|undefined} */ get follower() { - return this.env.models['mail.follower'].get(this.props.followerLocalId); + return this.messaging && this.messaging.models['mail.follower'].get(this.props.followerLocalId); } /** * @returns {mail.follower_subtype} */ get followerSubtype() { - return this.env.models['mail.follower_subtype'].get(this.props.followerSubtypeLocalId); + return this.messaging && this.messaging.models['mail.follower_subtype'].get(this.props.followerSubtypeLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.js b/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.js index a618ff0c7e8..9b4349a0c62 100644 --- a/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.js +++ b/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.js @@ -14,7 +14,7 @@ export class FollowerSubtypeList extends Component { * @returns {mail.follower_subtype_list} */ get followerSubtypeList() { - return this.env.models['mail.follower_subtype_list'].get(this.props.localId); + return this.messaging && this.messaging.models['mail.follower_subtype_list'].get(this.props.localId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/mail_template/mail_template.js b/addons/mail/static/src/components/mail_template/mail_template.js index 00688d948f3..377b779610e 100644 --- a/addons/mail/static/src/components/mail_template/mail_template.js +++ b/addons/mail/static/src/components/mail_template/mail_template.js @@ -14,14 +14,14 @@ export class MailTemplate extends Component { * @returns {mail.activity} */ get activity() { - return this.env.models['mail.activity'].get(this.props.activityLocalId); + return this.messaging && this.messaging.models['mail.activity'].get(this.props.activityLocalId); } /** * @returns {mail.mail_template} */ get mailTemplate() { - return this.env.models['mail.mail_template'].get(this.props.mailTemplateLocalId); + return this.messaging && this.messaging.models['mail.mail_template'].get(this.props.mailTemplateLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/message/message.js b/addons/mail/static/src/components/message/message.js index 6c88550acec..ef736a6320b 100644 --- a/addons/mail/static/src/components/message/message.js +++ b/addons/mail/static/src/components/message/message.js @@ -173,7 +173,7 @@ export class Message extends Component { * @returns {mail.message} */ get message() { - return this.env.models['mail.message'].get(this.props.messageLocalId); + return this.messaging && this.messaging.models['mail.message'].get(this.props.messageLocalId); } /** * @returns {string} @@ -217,7 +217,7 @@ export class Message extends Component { * @returns {mail.thread_view} */ get threadView() { - return this.env.models['mail.thread_view'].get(this.props.threadViewLocalId); + return this.messaging && this.messaging.models['mail.thread_view'].get(this.props.threadViewLocalId); } /** diff --git a/addons/mail/static/src/components/message_author_prefix/message_author_prefix.js b/addons/mail/static/src/components/message_author_prefix/message_author_prefix.js index 8fd23f0f415..e4e7e63174c 100644 --- a/addons/mail/static/src/components/message_author_prefix/message_author_prefix.js +++ b/addons/mail/static/src/components/message_author_prefix/message_author_prefix.js @@ -14,14 +14,14 @@ export class MessageAuthorPrefix extends Component { * @returns {mail.message} */ get message() { - return this.env.models['mail.message'].get(this.props.messageLocalId); + return this.messaging && this.messaging.models['mail.message'].get(this.props.messageLocalId); } /** * @returns {mail.thread|undefined} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } } diff --git a/addons/mail/static/src/components/message_list/message_list.js b/addons/mail/static/src/components/message_list/message_list.js index 60fcdf16c7b..27c94d40493 100644 --- a/addons/mail/static/src/components/message_list/message_list.js +++ b/addons/mail/static/src/components/message_list/message_list.js @@ -221,7 +221,7 @@ export class MessageList extends Component { .filter(([refId, ref]) => ( // Message refs have message local id as ref id, and message // local ids contain name of model 'mail.message'. - refId.includes(this.env.models['mail.message'].modelName) && + refId.includes(this.messaging.models['mail.message'].modelName) && // Component that should be destroyed but haven't just yet. ref.message ) @@ -308,7 +308,7 @@ export class MessageList extends Component { * @returns {mail.thread_view} */ get threadView() { - return this.env.models['mail.thread_view'].get(this.props.threadViewLocalId); + return this.messaging && this.messaging.models['mail.thread_view'].get(this.props.threadViewLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js b/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js index 6bff059d014..99238418e32 100644 --- a/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js +++ b/addons/mail/static/src/components/message_seen_indicator/message_seen_indicator.js @@ -76,7 +76,7 @@ export class MessageSeenIndicator extends Component { * @returns {mail.message} */ get message() { - return this.env.models['mail.message'].get(this.props.messageLocalId); + return this.messaging && this.messaging.models['mail.message'].get(this.props.messageLocalId); } /** @@ -86,7 +86,7 @@ export class MessageSeenIndicator extends Component { if (!this.thread || this.thread.model !== 'mail.channel') { return undefined; } - return this.env.models['mail.message_seen_indicator'].findFromIdentifyingData({ + return this.messaging.models['mail.message_seen_indicator'].findFromIdentifyingData({ channelId: this.thread.id, messageId: this.message.id, }); @@ -96,7 +96,7 @@ export class MessageSeenIndicator extends Component { * @returns {mail.Thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } } diff --git a/addons/mail/static/src/components/messaging_menu/messaging_menu.js b/addons/mail/static/src/components/messaging_menu/messaging_menu.js index abcc3c92f3c..70e0b8f609e 100644 --- a/addons/mail/static/src/components/messaging_menu/messaging_menu.js +++ b/addons/mail/static/src/components/messaging_menu/messaging_menu.js @@ -166,7 +166,7 @@ export class MessagingMenu extends Component { */ _onMobileNewMessageInputSource(req, res) { const value = _.escape(req.term); - this.env.models['mail.partner'].imSearch({ + this.messaging.models['mail.partner'].imSearch({ callback: partners => { const suggestions = partners.map(partner => { return { diff --git a/addons/mail/static/src/components/notification_group/notification_group.js b/addons/mail/static/src/components/notification_group/notification_group.js index 588c9c0a8d1..c7b26749b17 100644 --- a/addons/mail/static/src/components/notification_group/notification_group.js +++ b/addons/mail/static/src/components/notification_group/notification_group.js @@ -27,7 +27,7 @@ export class NotificationGroup extends Component { * @returns {mail.notification_group} */ get group() { - return this.env.models['mail.notification_group'].get(this.props.notificationGroupLocalId); + return this.messaging && this.messaging.models['mail.notification_group'].get(this.props.notificationGroupLocalId); } /** diff --git a/addons/mail/static/src/components/notification_list/notification_list.js b/addons/mail/static/src/components/notification_list/notification_list.js index 2e1022ba655..893e3d96431 100644 --- a/addons/mail/static/src/components/notification_list/notification_list.js +++ b/addons/mail/static/src/components/notification_list/notification_list.js @@ -18,11 +18,14 @@ export class NotificationList extends Component { * @returns {Object[]} */ get notifications() { + if (!this.messaging) { + return []; + } const threads = this._getThreads(this.props); let threadNeedactionNotifications = []; if (this.props.filter === 'all') { // threads with needactions - threadNeedactionNotifications = this.env.models['mail.thread'] + threadNeedactionNotifications = this.messaging.models['mail.thread'] .all(t => t.model !== 'mail.box' && t.needactionMessagesAsOriginThread.length > 0) .sort((t1, t2) => { if (t1.needactionMessagesAsOriginThread.length > 0 && t2.needactionMessagesAsOriginThread.length === 0) { @@ -113,7 +116,7 @@ export class NotificationList extends Component { const threads = this.notifications .filter(notification => notification.thread && notification.thread.exists()) .map(notification => notification.thread); - this.env.models['mail.thread'].loadPreviews(threads); + this.messaging.models['mail.thread'].loadPreviews(threads); } /** @@ -124,7 +127,7 @@ export class NotificationList extends Component { */ _getThreads(props) { if (props.filter === 'mailbox') { - return this.env.models['mail.thread'] + return this.messaging.models['mail.thread'] .all(thread => thread.isPinned && thread.model === 'mail.box') .sort((mailbox1, mailbox2) => { if (mailbox1 === this.env.messaging.inbox) { @@ -144,7 +147,7 @@ export class NotificationList extends Component { mailbox1Name < mailbox2Name ? -1 : 1; }); } else if (props.filter === 'channel') { - return this.env.models['mail.thread'] + return this.messaging.models['mail.thread'] .all(thread => thread.channel_type === 'channel' && thread.isPinned && @@ -152,7 +155,7 @@ export class NotificationList extends Component { ) .sort((c1, c2) => c1.displayName < c2.displayName ? -1 : 1); } else if (props.filter === 'chat') { - return this.env.models['mail.thread'] + return this.messaging.models['mail.thread'] .all(thread => thread.isChatChannel && thread.isPinned && @@ -161,7 +164,7 @@ export class NotificationList extends Component { .sort((c1, c2) => c1.displayName < c2.displayName ? -1 : 1); } else if (props.filter === 'all') { // "All" filter is for channels and chats - return this.env.models['mail.thread'] + return this.messaging.models['mail.thread'] .all(thread => thread.isPinned && thread.model === 'mail.channel') .sort((c1, c2) => c1.displayName < c2.displayName ? -1 : 1); } else { diff --git a/addons/mail/static/src/components/notification_popover/notification_popover.js b/addons/mail/static/src/components/notification_popover/notification_popover.js index bc27580a512..0673640aa4e 100644 --- a/addons/mail/static/src/components/notification_popover/notification_popover.js +++ b/addons/mail/static/src/components/notification_popover/notification_popover.js @@ -48,8 +48,11 @@ export class NotificationPopover extends Component { * @returns {mail.notification[]} */ get notifications() { + if (!this.messaging) { + return []; + } return this.props.notificationLocalIds.map( - notificationLocalId => this.env.models['mail.notification'].get(notificationLocalId) + notificationLocalId => this.messaging.models['mail.notification'].get(notificationLocalId) ); } diff --git a/addons/mail/static/src/components/partner_im_status_icon/partner_im_status_icon.js b/addons/mail/static/src/components/partner_im_status_icon/partner_im_status_icon.js index c73c76df748..125cd769baa 100644 --- a/addons/mail/static/src/components/partner_im_status_icon/partner_im_status_icon.js +++ b/addons/mail/static/src/components/partner_im_status_icon/partner_im_status_icon.js @@ -14,7 +14,7 @@ export class PartnerImStatusIcon extends Component { * @returns {mail.partner} */ get partner() { - return this.env.models['mail.partner'].get(this.props.partnerLocalId); + return this.messaging && this.messaging.models['mail.partner'].get(this.props.partnerLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/thread_icon/thread_icon.js b/addons/mail/static/src/components/thread_icon/thread_icon.js index 241902d838f..c0b4a449e1b 100644 --- a/addons/mail/static/src/components/thread_icon/thread_icon.js +++ b/addons/mail/static/src/components/thread_icon/thread_icon.js @@ -14,7 +14,7 @@ export class ThreadIcon extends Component { * @returns {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } } diff --git a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js index 670a453c97c..b1bba2fb85b 100644 --- a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js +++ b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js @@ -59,7 +59,7 @@ export class ThreadNeedactionPreview extends Component { * @returns {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } //-------------------------------------------------------------------------- @@ -87,7 +87,7 @@ export class ThreadNeedactionPreview extends Component { * @param {MouseEvent} ev */ _onClickMarkAsRead(ev) { - this.env.models['mail.message'].markAllAsRead([ + this.messaging.models['mail.message'].markAllAsRead([ ['model', '=', this.thread.model], ['res_id', '=', this.thread.id], ]); diff --git a/addons/mail/static/src/components/thread_preview/thread_preview.js b/addons/mail/static/src/components/thread_preview/thread_preview.js index 514646b9692..6775bb1e8a6 100644 --- a/addons/mail/static/src/components/thread_preview/thread_preview.js +++ b/addons/mail/static/src/components/thread_preview/thread_preview.js @@ -53,7 +53,7 @@ export class ThreadPreview extends Component { * @returns {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status.js b/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status.js index 8be4841d0a5..c132f0894a8 100644 --- a/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status.js +++ b/addons/mail/static/src/components/thread_textual_typing_status/thread_textual_typing_status.js @@ -14,7 +14,7 @@ export class ThreadTextualTypingStatus extends Component { * @returns {mail.thread} */ get thread() { - return this.env.models['mail.thread'].get(this.props.threadLocalId); + return this.messaging && this.messaging.models['mail.thread'].get(this.props.threadLocalId); } } diff --git a/addons/mail/static/src/components/thread_view/thread_view.js b/addons/mail/static/src/components/thread_view/thread_view.js index b52424e982b..299e77f6ad2 100644 --- a/addons/mail/static/src/components/thread_view/thread_view.js +++ b/addons/mail/static/src/components/thread_view/thread_view.js @@ -86,7 +86,7 @@ export class ThreadView extends Component { * @returns {mail.thread_view} */ get threadView() { - return this.env.models['mail.thread_view'].get(this.props.threadViewLocalId); + return this.messaging && this.messaging.models['mail.thread_view'].get(this.props.threadViewLocalId); } //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/components/thread_view_topbar/thread_view_topbar.js b/addons/mail/static/src/components/thread_view_topbar/thread_view_topbar.js index a163ab75538..a2e5ac9b444 100644 --- a/addons/mail/static/src/components/thread_view_topbar/thread_view_topbar.js +++ b/addons/mail/static/src/components/thread_view_topbar/thread_view_topbar.js @@ -25,7 +25,7 @@ export class ThreadViewTopbar extends Component { * @returns {mail.thread_view_topbar} */ get threadViewTopBar() { - return this.env.models['mail.thread_view_topbar'].get(this.props.localId); + return this.messaging && this.messaging.models['mail.thread_view_topbar'].get(this.props.localId); } } diff --git a/addons/mail/static/src/main.js b/addons/mail/static/src/main.js index 7d4a8761c8d..b31f06ebc31 100644 --- a/addons/mail/static/src/main.js +++ b/addons/mail/static/src/main.js @@ -21,10 +21,5 @@ Object.defineProperty(env, 'messaging', { return this.services.messaging.modelManager.messaging; }, }); -Object.defineProperty(env, 'models', { - get() { - return this.services.messaging.modelManager.models; - }, -}); serviceRegistry.add('messaging', MessagingService); diff --git a/addons/mail/static/src/utils/messaging_component.js b/addons/mail/static/src/utils/messaging_component.js index db709ad42ac..8264bc15145 100644 --- a/addons/mail/static/src/utils/messaging_component.js +++ b/addons/mail/static/src/utils/messaging_component.js @@ -25,7 +25,7 @@ export function registerMessagingComponent(ComponentClass, { propsCompareDepth = const decoratedName = `@messaging ${name}`; // Defining the class in an object and immediately taking it out so that it // has "decoratedName" as its class name in stack traces and stuff. - const MessagingClass = {[decoratedName]: class extends ComponentClass { + const MessagingClass = { [decoratedName]: class extends ComponentClass { setup(...args) { super.setup(...args); // useModels must be defined after useRenderedValues, indeed records and @@ -34,7 +34,10 @@ export function registerMessagingComponent(ComponentClass, { propsCompareDepth = useModels(); useShouldUpdateBasedOnProps({ propsCompareDepth }); } - }}[decoratedName]; + get messaging() { + return this.env.services.messaging.modelManager.messaging; + } + } }[decoratedName]; // Create an object whose prototype is the component registry with the values of the original // Component.components. This means that trying to get a value from this object will first look // into the original Component's components, and fall back on the registry if not found. diff --git a/addons/mail/static/src/utils/test_utils.js b/addons/mail/static/src/utils/test_utils.js index 6231ca33751..19f4ec2b531 100644 --- a/addons/mail/static/src/utils/test_utils.js +++ b/addons/mail/static/src/utils/test_utils.js @@ -555,11 +555,6 @@ async function start(param0 = {}) { return this.services.messaging.modelManager.messaging; }, }); - Object.defineProperty(env, 'models', { - get() { - return this.services.messaging.modelManager.models; - }, - }); this._super(env); }, /** diff --git a/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js b/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js index c53ccbff837..21d03f7b7d5 100644 --- a/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js +++ b/addons/snailmail/static/src/components/snailmail_error_dialog/snailmail_error_dialog.js @@ -37,7 +37,7 @@ class SnailmailErrorDialog extends Component { * @returns {mail.message} */ get message() { - return this.env.models['mail.message'].get(this.props.messageLocalId); + return this.messaging && this.messaging.models['mail.message'].get(this.props.messageLocalId); } /** diff --git a/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js index c0bfa6a5066..50ce7b3e3bd 100644 --- a/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js +++ b/addons/snailmail/static/src/components/snailmail_notification_popover/snailmail_notification_popover.js @@ -43,7 +43,7 @@ class SnailmailNotificationPopover extends Component { * @returns {mail.message} */ get message() { - return this.env.models['mail.message'].get(this.props.messageLocalId); + return this.messaging && this.messaging.models['mail.message'].get(this.props.messageLocalId); } /** diff --git a/addons/website_livechat/static/src/components/visitor_banner/visitor_banner.js b/addons/website_livechat/static/src/components/visitor_banner/visitor_banner.js index fd5a437dfe3..30949e6415e 100644 --- a/addons/website_livechat/static/src/components/visitor_banner/visitor_banner.js +++ b/addons/website_livechat/static/src/components/visitor_banner/visitor_banner.js @@ -15,7 +15,7 @@ class VisitorBanner extends Component { * @returns {website_livechat.visitor} */ get visitor() { - return this.env.models['website_livechat.visitor'].get(this.props.visitorLocalId); + return this.messaging && this.messaging.models['website_livechat.visitor'].get(this.props.visitorLocalId); } }