From ecd4cba040837d7539770cb1ec22e050ee6557a5 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Thu, 28 Jul 2022 09:07:34 +0000 Subject: [PATCH] [FIX] mail: runbot error accessing messaging on undefined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fixes the 4427 runbot error. closes odoo/odoo#96966 Signed-off-by: Sébastien Theys (seb) --- addons/mail/static/src/models/composer_view.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/mail/static/src/models/composer_view.js b/addons/mail/static/src/models/composer_view.js index 2b03e04bd5b..2f1966c24d5 100644 --- a/addons/mail/static/src/models/composer_view.js +++ b/addons/mail/static/src/models/composer_view.js @@ -592,12 +592,16 @@ registerModel({ const chatter = this.chatter; const { thread: chatterThread } = this.chatter || {}; const { thread: threadViewThread } = threadView; + // Keep a reference to messaging: composer could be + // unmounted while awaiting the prc promise. In this + // case, this would be undefined. + const messaging = this.messaging; const messageData = await this.messaging.rpc({ route: `/mail/message/post`, params }); - if (!this.messaging) { + if (!messaging.exists()) { return; } - const message = this.messaging.models['Message'].insert( - this.messaging.models['Message'].convertData(messageData) + const message = messaging.models['Message'].insert( + messaging.models['Message'].convertData(messageData) ); for (const threadView of message.originThread.threadViews) { // Reset auto scroll to be able to see the newly posted message. @@ -617,9 +621,9 @@ registerModel({ } } if (threadViewThread) { - if (threadViewThread === this.messaging.inbox) { - this.messaging.notify({ - message: sprintf(this.env._t(`Message posted on "%s"`), message.originThread.displayName), + if (threadViewThread === messaging.inbox) { + messaging.notify({ + message: sprintf(messaging.env._t(`Message posted on "%s"`), message.originThread.displayName), type: 'info', }); if (this.exists()) {