From 87dc6a035d9938659ccd9131cf1c02c08e227375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 8 Jun 2022 14:46:46 +0000 Subject: [PATCH] [IMP] mail: move hasParentReloadOnFollowersUpdate code to models Remove code from legacy form in preparation of Owl form. Part of task-2871070 Part-of: odoo/odoo#93273 --- .../chatter_container/chatter_container.js | 4 +++ .../follower_list_menu/follower_list_menu.js | 2 +- addons/mail/static/src/models/chatter.js | 34 ++++++++++++++++++ addons/mail/static/src/models/thread.js | 35 ------------------- .../widgets/form_renderer/form_renderer.js | 7 +--- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/addons/mail/static/src/components/chatter_container/chatter_container.js b/addons/mail/static/src/components/chatter_container/chatter_container.js index 0b0a0fb00a5..2f1e38045dc 100644 --- a/addons/mail/static/src/components/chatter_container/chatter_container.js +++ b/addons/mail/static/src/components/chatter_container/chatter_container.js @@ -117,6 +117,10 @@ Object.assign(ChatterContainer, { type: Boolean, optional: true, }, + hasParentReloadOnFollowersUpdate: { + type: Boolean, + optional: true, + }, hasTopbarCloseButton: { type: Boolean, optional: true, 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 2093b9e2f4f..b68c9a44c8f 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 @@ -47,7 +47,7 @@ export class FollowerListMenu extends Component { _onClickAddFollowers(ev) { ev.preventDefault(); this.followerListMenuView.hide(); - this.followerListMenuView.chatterOwner.thread.promptAddPartnerFollower(); + this.followerListMenuView.chatterOwner.promptAddPartnerFollower(); } /** diff --git a/addons/mail/static/src/models/chatter.js b/addons/mail/static/src/models/chatter.js index e694b056214..cfa6bca3a03 100644 --- a/addons/mail/static/src/models/chatter.js +++ b/addons/mail/static/src/models/chatter.js @@ -119,6 +119,37 @@ registerModel({ openAttachmentBoxView() { this.update({ attachmentBoxView: insertAndReplace() }); }, + /** + * Open a dialog to add partners as followers. + */ + promptAddPartnerFollower() { + const action = { + type: 'ir.actions.act_window', + res_model: 'mail.wizard.invite', + view_mode: 'form', + views: [[false, 'form']], + name: this.env._t("Invite Follower"), + target: 'new', + context: { + default_res_model: this.thread.model, + default_res_id: this.thread.id, + }, + }; + this.env.services.action.doAction( + action, + { + onClose: async () => { + if (!this.exists() && !this.thread) { + return; + } + await this.thread.fetchData(['followers']); + if (this.exists() && this.hasParentReloadOnFollowersUpdate) { + this.reloadParentView(); + } + }, + } + ); + }, async refresh() { const requestData = ['activities', 'followers', 'suggestedRecipients']; if (this.hasMessageList) { @@ -388,6 +419,9 @@ registerModel({ hasParentReloadOnAttachmentsChanged: attr({ default: false, }), + hasParentReloadOnFollowersUpdate: attr({ + default: false, + }), /** * Determines whether `this.thread` should be displayed. */ diff --git a/addons/mail/static/src/models/thread.js b/addons/mail/static/src/models/thread.js index a4cae1caae1..5097d693209 100644 --- a/addons/mail/static/src/models/thread.js +++ b/addons/mail/static/src/models/thread.js @@ -873,12 +873,6 @@ registerModel({ } await this.notifyPinStateToServer(); }, - /** - * Open a dialog to add partners as followers. - */ - promptAddPartnerFollower() { - this._promptAddFollower(); - }, /** * Refresh the typing status of the current partner. */ @@ -1687,35 +1681,6 @@ registerModel({ }); } }, - /** - * @private - */ - _promptAddFollower() { - const action = { - type: 'ir.actions.act_window', - res_model: 'mail.wizard.invite', - view_mode: 'form', - views: [[false, 'form']], - name: this.env._t("Invite Follower"), - target: 'new', - context: { - default_res_model: this.model, - default_res_id: this.id, - }, - }; - this.env.services.action.doAction( - action, - { - onClose: async () => { - if (!this.exists()) { - return; - } - await this.fetchData(['followers']); - owl.Component.env.bus.trigger('Thread:promptAddFollower-closed'); - }, - } - ); - }, /** * @private * @returns {Array[]} diff --git a/addons/mail/static/src/widgets/form_renderer/form_renderer.js b/addons/mail/static/src/widgets/form_renderer/form_renderer.js index 14a16506ca2..dc0a4576dcb 100644 --- a/addons/mail/static/src/widgets/form_renderer/form_renderer.js +++ b/addons/mail/static/src/widgets/form_renderer/form_renderer.js @@ -5,8 +5,6 @@ import { ChatterContainer } from '@mail/components/chatter_container/chatter_con import FormRenderer from 'web.FormRenderer'; import { ComponentWrapper } from 'web.OwlCompatibility'; -const { Component } = owl; - class ChatterContainerWrapperComponent extends ComponentWrapper {} /** @@ -44,7 +42,6 @@ FormRenderer.include({ this._chatterContainerComponent = undefined; this.off('o_chatter_rendered', this); this.off('o_message_posted', this); - Component.env.bus.off('Thread:promptAddFollower-closed', this); }, //-------------------------------------------------------------------------- @@ -79,9 +76,6 @@ FormRenderer.include({ this.trigger_up('reload', { keepChanges: true }); }); } - if (this.chatterFields.hasRecordReloadOnFollowersUpdate) { - Component.env.bus.on('Thread:promptAddFollower-closed', this, ev => this.trigger_up('reload', { keepChanges: true })); - } }, /** * @private @@ -93,6 +87,7 @@ FormRenderer.include({ hasFollowers: this.chatterFields.hasMessageFollowerIds, hasMessageList: this.chatterFields.hasMessageIds, hasParentReloadOnAttachmentsChanged: this.chatterFields.hasRecordReloadOnAttachmentsChanged, + hasParentReloadOnFollowersUpdate: this.chatterFields.hasRecordReloadOnFollowersUpdate, isAttachmentBoxVisibleInitially: this.chatterFields.isAttachmentBoxVisibleInitially, threadId: this.state.res_id, threadModel: this.state.model,