diff --git a/addons/mail/static/src/model/model_core.js b/addons/mail/static/src/model/model_core.js index 1c485cb17b8..592562a7537 100644 --- a/addons/mail/static/src/model/model_core.js +++ b/addons/mail/static/src/model/model_core.js @@ -190,7 +190,7 @@ function assertIsFunction(toAssert) { * @throws {Error} if name is not an existing hook name. */ function assertIsValidHookName(name) { - const validHookNames = new Set(['_created', '_willCreate', '_willDelete']); + const validHookNames = new Set(['_created', '_willDelete']); if (!validHookNames.has(name)) { throw new Error("invalid hook name."); } diff --git a/addons/mail/static/src/model/model_manager.js b/addons/mail/static/src/model/model_manager.js index e8097c8d7ff..7216dc15e83 100644 --- a/addons/mail/static/src/model/model_manager.js +++ b/addons/mail/static/src/model/model_manager.js @@ -709,15 +709,6 @@ export class ModelManager { for (const methodName of recordMethods.keys()) { record[methodName] = record[methodName].bind(record); } - /** - * Invoke the life-cycle hook `_willCreate.` - * After this step the record is in a functioning state and it is - * considered existing. - */ - const lifecycleHooks = registry.get(model.name).get('lifecycleHooks'); - if (lifecycleHooks.has('_willCreate')) { - lifecycleHooks.get('_willCreate').call(record); - } /** * Register post processing operation that are to be delayed at * the end of the update cycle. diff --git a/addons/mail/static/src/models/composer_view.js b/addons/mail/static/src/models/composer_view.js index abc195b532e..3a88d060a5e 100644 --- a/addons/mail/static/src/models/composer_view.js +++ b/addons/mail/static/src/models/composer_view.js @@ -14,25 +14,10 @@ registerModel({ name: 'ComposerView', identifyingFields: [['threadView', 'messageViewInEditing', 'chatter']], lifecycleHooks: { - _willCreate() { - /** - * Determines whether there is a mention RPC currently in progress. - * Useful to queue a new call if there is already one pending. - */ - this._hasMentionRpcInProgress = false; - /** - * Determines the next function to execute after the current mention - * RPC is done, if any. - */ - this._nextMentionRpcFunction = undefined; - }, _created() { document.addEventListener('click', this.onClickCaptureGlobal, true); }, _willDelete() { - // Clears the mention queue on deleting the record to prevent - // unnecessary RPC. - this._nextMentionRpcFunction = undefined; document.removeEventListener('click', this.onClickCaptureGlobal, true); }, }, @@ -1133,17 +1118,19 @@ registerModel({ * @param {function} func */ async _executeOrQueueFunction(func) { - if (this._hasMentionRpcInProgress) { - this._nextMentionRpcFunction = func; + if (this.hasMentionRpcInProgress) { + this.update({ nextMentionRpcFunction: func }); return; } - this._hasMentionRpcInProgress = true; - this._nextMentionRpcFunction = undefined; + this.update({ + hasMentionRpcInProgress: true, + nextMentionRpcFunction: clear(), + }); await func(); if (this.exists()) { - this._hasMentionRpcInProgress = false; - if (this._nextMentionRpcFunction) { - this._executeOrQueueFunction(this._nextMentionRpcFunction); + this.update({ hasMentionRpcInProgress: false }); + if (this.nextMentionRpcFunction) { + this._executeOrQueueFunction(this.nextMentionRpcFunction); } } }, @@ -1501,6 +1488,13 @@ registerModel({ hasHeader: attr({ compute: '_computeHasHeader', }), + /** + * Determines whether there is a mention RPC currently in progress. + * Useful to queue a new call if there is already one pending. + */ + hasMentionRpcInProgress: attr({ + default: false, + }), hasMentionSuggestionsBelowPosition: attr({ compute: '_computeHasMentionSuggestionsBelowPosition', default: false, @@ -1574,6 +1568,11 @@ registerModel({ * properly without flicker. */ mirroredTextareaRef: attr(), + /** + * Determines the next function to execute after the current mention + * RPC is done, if any. + */ + nextMentionRpcFunction: attr(), /** * Determines the label on the send button of this composer view. */ diff --git a/addons/mail/static/src/models/record.js b/addons/mail/static/src/models/record.js index 2e34a845301..25531417b18 100644 --- a/addons/mail/static/src/models/record.js +++ b/addons/mail/static/src/models/record.js @@ -26,19 +26,6 @@ registerModel({ */ identifyingFields: ['messaging'], lifecycleHooks: { - /** - * This function is called during the create cycle, when the record has - * already been created, but its values have not yet been assigned. - * - * It is usually preferable to use @see `_created`. - * - * The main use case is to prepare the record for the assignation of its - * values, for example if a computed field relies on the record to have - * some purely technical property correctly set. - * - * @private - */ - _willCreate() {}, /** * This function is called after the record has been created, more * precisely at the end of the update cycle (which means all implicit