summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models
diff options
context:
space:
mode:
authorDidier (did) <did@odoo.com>2020-09-21 15:44:21 +0000
committerSébastien Theys <seb@odoo.com>2020-09-21 16:49:47 +0000
commitde1f701e7bd7ebb6f7ebea5c097d980039c4f904 (patch)
treed4b931794a6200ebce8809ff73400d65dc391e56 /addons/mail/static/src/models
parentaaec45b9aece17f8c764cd7a89eb243a5fc11924 (diff)
[FIX] mail: restore the "to followers" feature
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) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models')
-rw-r--r--addons/mail/static/src/models/chatter/chatter.js1
-rw-r--r--addons/mail/static/src/models/composer/composer.js59
-rw-r--r--addons/mail/static/src/models/follower/follower.js2
-rw-r--r--addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js116
-rw-r--r--addons/mail/static/src/models/thread/thread.js56
5 files changed, 228 insertions, 6 deletions
diff --git a/addons/mail/static/src/models/chatter/chatter.js b/addons/mail/static/src/models/chatter/chatter.js
index a94731910bc..23e98a956a9 100644
--- a/addons/mail/static/src/models/chatter/chatter.js
+++ b/addons/mail/static/src/models/chatter/chatter.js
@@ -193,6 +193,7 @@ function factory(dependencies) {
) {
if (this.thread) {
this.thread.refreshFollowers();
+ this.thread.fetchAndUpdateSuggestedRecipients();
}
}
if (
diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js
index d51f8c37249..230541c77ef 100644
--- a/addons/mail/static/src/models/composer/composer.js
+++ b/addons/mail/static/src/models/composer/composer.js
@@ -79,6 +79,22 @@ function factory(dependencies) {
}
/**
+ * @private
+ * @returns {mail.partner[]}
+ */
+ _computeRecipients() {
+ const recipients = [...this.mentionedPartners];
+ if (this.thread) {
+ for (const recipient of this.thread.suggestedRecipientInfoList) {
+ if (recipient.isSelected) {
+ recipients.push(recipient.partner);
+ }
+ }
+ }
+ return [['replace', recipients]];
+ }
+
+ /**
* Open the full composer modal.
*/
async openFullComposer() {
@@ -89,8 +105,7 @@ function factory(dependencies) {
default_body: mailUtils.escapeAndCompactTextContent(this.textInputContent),
default_is_log: this.isLog,
default_model: this.thread.model,
- /* FIXME would need to use suggested_partners here task-2280157 */
- // default_partner_ids: partnerIds,
+ default_partner_ids: this.recipients.map(partner => partner.id),
default_res_id: this.thread.id,
mail_post_autofollow: true,
};
@@ -135,8 +150,11 @@ function factory(dependencies) {
let postData = {
attachment_ids: this.attachments.map(attachment => attachment.id),
body,
- partner_ids: this.mentionedPartners.map(partner => partner.id),
+ context: {
+ mail_post_autofollow: true,
+ },
message_type: 'comment',
+ partner_ids: this.recipients.map(partner => partner.id),
};
if (this.subjectContent) {
postData.subject = this.subjectContent;
@@ -152,7 +170,7 @@ function factory(dependencies) {
model: 'mail.channel',
method: command ? 'execute_command' : 'message_post',
args: [thread.id],
- kwargs: postData
+ kwargs: postData,
}));
} else {
Object.assign(postData, {
@@ -162,12 +180,12 @@ function factory(dependencies) {
model: thread.model,
method: 'message_post',
args: [thread.id],
- kwargs: postData
+ kwargs: postData,
}));
const [messageData] = await this.async(() => this.env.services.rpc({
model: 'mail.message',
method: 'message_format',
- args: [[messageId]]
+ args: [[messageId]],
}));
this.env.models['mail.message'].insert(Object.assign(
{},
@@ -184,6 +202,8 @@ function factory(dependencies) {
for (const threadView of this.thread.threadViews) {
threadView.addComponentHint('current-partner-just-posted-message', { messageId });
}
+ thread.refreshFollowers();
+ thread.fetchAndUpdateSuggestedRecipients();
this._reset();
}
@@ -614,6 +634,33 @@ function factory(dependencies) {
dependencies: ['textInputContent'],
}),
/**
+ * Determines the extra `mail.partner` (on top of existing followers)
+ * that will receive the message being composed by `this`, and that will
+ * also be added as follower of `this.thread`.
+ */
+ recipients: many2many('mail.partner', {
+ compute: '_computeRecipients',
+ dependencies: [
+ 'mentionedPartners',
+ 'threadSuggestedRecipientInfoListIsSelected',
+ // FIXME thread.suggestedRecipientInfoList.partner should be a
+ // dependency, but it is currently impossible to have a related
+ // m2o through a m2m. task-2261221
+ ]
+ }),
+ /**
+ * Serves as compute dependency.
+ */
+ threadSuggestedRecipientInfoList: many2many('mail.suggested_recipient_info', {
+ related: 'thread.suggestedRecipientInfoList',
+ }),
+ /**
+ * Serves as compute dependency.
+ */
+ threadSuggestedRecipientInfoListIsSelected: attr({
+ related: 'threadSuggestedRecipientInfoList.isSelected',
+ }),
+ /**
* Composer subject input content.
*/
subjectContent: attr({
diff --git a/addons/mail/static/src/models/follower/follower.js b/addons/mail/static/src/models/follower/follower.js
index 6bc6c7f579f..183c20e4684 100644
--- a/addons/mail/static/src/models/follower/follower.js
+++ b/addons/mail/static/src/models/follower/follower.js
@@ -89,7 +89,9 @@ function factory(dependencies) {
method: 'message_unsubscribe',
args: [[this.followedThread.id], partner_ids, channel_ids]
}));
+ const followedThread = this.followedThread;
this.delete();
+ followedThread.fetchAndUpdateSuggestedRecipients();
}
/**
diff --git a/addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js b/addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js
new file mode 100644
index 00000000000..c8f128569a6
--- /dev/null
+++ b/addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js
@@ -0,0 +1,116 @@
+odoo.define('mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js', function (require) {
+'use strict';
+
+const { registerNewModel } = require('mail/static/src/model/model_core.js');
+const { attr, many2one } = require('mail/static/src/model/model_field.js');
+
+function factory(dependencies) {
+
+ class SuggestedRecipientInfo extends dependencies['mail.model'] {
+
+ //----------------------------------------------------------------------
+ // private
+ //----------------------------------------------------------------------
+
+ /**
+ * @private
+ * @returns {string}
+ */
+ _computeEmail() {
+ return this.partner && this.partner.email || this.email;
+ }
+
+ /**
+ * Prevents selecting a recipient that does not have a partner.
+ *
+ * @private
+ * @returns {boolean}
+ */
+ _computeIsSelected() {
+ return this.partner ? this.isSelected : false;
+ }
+
+ /**
+ * @private
+ * @returns {string}
+ */
+ _computeName() {
+ return this.partner && this.partner.nameOrDisplayName || this.name;
+ }
+
+ }
+
+ SuggestedRecipientInfo.fields = {
+ /**
+ * Determines the email of `this`. It serves as visual clue when
+ * displaying `this`, and also serves as default partner email when
+ * creating a new partner from `this`.
+ */
+ email: attr({
+ compute: '_computeEmail',
+ dependencies: [
+ 'email',
+ 'partnerEmail',
+ ],
+ }),
+ /**
+ * Determines whether `this` will be added to recipients when posting a
+ * new message on `this.thread`.
+ */
+ isSelected: attr({
+ compute: '_computeIsSelected',
+ default: true,
+ dependencies: [
+ 'isSelected',
+ 'partner',
+ ],
+ }),
+ /**
+ * Determines the name of `this`. It serves as visual clue when
+ * displaying `this`, and also serves as default partner name when
+ * creating a new partner from `this`.
+ */
+ name: attr({
+ compute: '_computeName',
+ dependencies: [
+ 'name',
+ 'partnerNameOrDisplayName',
+ ],
+ }),
+ /**
+ * Determines the optional `mail.partner` associated to `this`.
+ */
+ partner: many2one('mail.partner'),
+ /**
+ * Serves as compute dependency.
+ */
+ partnerEmail: attr({
+ related: 'partner.email'
+ }),
+ /**
+ * Serves as compute dependency.
+ */
+ partnerNameOrDisplayName: attr({
+ related: 'partner.nameOrDisplayName'
+ }),
+ /**
+ * Determines why `this` is a suggestion for `this.thread`. It serves as
+ * visual clue when displaying `this`.
+ */
+ reason: attr(),
+ /**
+ * Determines the `mail.thread` concerned by `this.`
+ */
+ thread: many2one('mail.thread', {
+ inverse: 'suggestedRecipientInfoList',
+ }),
+ };
+
+ SuggestedRecipientInfo.modelName = 'mail.suggested_recipient_info';
+
+ return SuggestedRecipientInfo;
+}
+
+registerNewModel('mail.suggested_recipient_info', factory);
+
+});
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) {
@@ -419,6 +420,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}
*/
@@ -459,6 +495,19 @@ function factory(dependencies) {
}
/**
+ * 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.
*/
async follow() {
@@ -472,6 +521,7 @@ function factory(dependencies) {
},
}));
this.refreshFollowers();
+ this.fetchAndUpdateSuggestedRecipients();
}
/**
@@ -1594,6 +1644,12 @@ function factory(dependencies) {
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.
*/