From de1f701e7bd7ebb6f7ebea5c097d980039c4f904 Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Mon, 21 Sep 2020 15:44:21 +0000 Subject: [FIX] mail: restore the "to followers" feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the "to followers" message inside the chatter composer was missing. Fix also some padding issue. This also restore the form dialog when you try to send a message to a suggested recipient that doesn't have a partner (someone in CC email for eg). But now, suggested recipient without partner are unchecked by default and the form open when the user try to check them. If the user discard the form dialog, the suggested recipient isn't checked. This is better since only a partner will receive a notification. task-2280157 closes odoo/odoo#58160 X-original-commit: 67d151cc36871d87b92676357a31a70de5a92fce Signed-off-by: Sébastien Theys (seb) --- addons/mail/static/src/models/thread/thread.js | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'addons/mail/static/src/models/thread/thread.js') diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index 75a53f67259..6eaed09ad8b 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -5,6 +5,7 @@ const { registerNewModel } = require('mail/static/src/model/model_core.js'); const { attr, many2many, many2one, one2many, one2one } = require('mail/static/src/model/model_field.js'); const throttle = require('mail/static/src/utils/throttle/throttle.js'); const Timer = require('mail/static/src/utils/timer/timer.js'); +const mailUtils = require('mail.utils'); function factory(dependencies) { @@ -418,6 +419,41 @@ function factory(dependencies) { ); } + /** + * Performs RPC on the route `/mail/get_suggested_recipients`. + * + * @static + * @param {Object} param0 + * @param {string} param0.model + * @param {integer[]} param0.res_id + */ + static async performRpcMailGetSuggestedRecipients({ model, res_ids }) { + const data = await this.env.services.rpc({ + route: '/mail/get_suggested_recipients', + params: { + model, + res_ids, + }, + }); + for (const id in data) { + const recipientInfoList = data[id].map(recipientInfoData => { + const [partner_id, emailInfo, reason] = recipientInfoData; + const [name, email] = emailInfo && mailUtils.parseEmail(emailInfo); + return { + email, + name, + partner: [partner_id ? ['insert', { id: partner_id }] : ['unlink']], + reason, + }; + }); + this.insert({ + id: parseInt(id), + model, + suggestedRecipientInfoList: [['insert-and-replace', recipientInfoList]], + }); + } + } + /** * @param {string} [stringifiedDomain='[]'] * @returns {mail.thread_cache} @@ -458,6 +494,19 @@ function factory(dependencies) { this.update({ areAttachmentsLoaded: true }); } + /** + * Fetches suggested recipients. + */ + async fetchAndUpdateSuggestedRecipients() { + if (this.isTemporary) { + return; + } + return this.env.models['mail.thread'].performRpcMailGetSuggestedRecipients({ + model: this.model, + res_ids: [this.id], + }); + } + /** * Add current user to provided thread's followers. */ @@ -472,6 +521,7 @@ function factory(dependencies) { }, })); this.refreshFollowers(); + this.fetchAndUpdateSuggestedRecipients(); } /** @@ -1593,6 +1643,12 @@ function factory(dependencies) { serverMessageUnreadCounter: attr({ default: 0, }), + /** + * Determines the `mail.suggested_recipient_info` concerning `this`. + */ + suggestedRecipientInfoList: one2many('mail.suggested_recipient_info', { + inverse: 'thread', + }), /** * Members that are currently typing something in the composer of this * thread, including current partner. -- cgit v1.2.3