From 39f14ca2c92a617bd387d5a29d69479f90d92a44 Mon Sep 17 00:00:00 2001 From: Renaud Thiry Date: Thu, 4 May 2023 11:33:13 +0000 Subject: [PATCH] [IMP] mail: add auto_comment message type Currently some auto_reply templates are internal as a means to prevent notifying users everytime we send a reply to somebody. This raises the issue that since responses to internal notifications are themselves internal notifications, often nobody will be notified of responses to these automated messages. We fix this by marking these messages as auto_comments, which will ensure responses to these messages are considered non-internal (and thus 'discussions', by default). task-2834304 closes odoo/odoo#94018 Related: odoo/enterprise#35466 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/models/mail_message.py | 1 + addons/mail/models/mail_thread.py | 18 +++++--- addons/mail/static/src/core/message_model.js | 4 ++ addons/mail/static/src/core_ui/message.js | 3 ++ addons/mail/static/src/core_ui/message.xml | 8 ++-- .../static/src/core_ui/message_reactions.xml | 4 +- addons/mail/wizard/mail_compose_message.py | 1 + addons/test_mail/tests/test_mail_gateway.py | 42 +++++++++++++++++ addons/test_mail/tests/test_message_track.py | 45 +++++++++++++++++++ 9 files changed, 115 insertions(+), 11 deletions(-) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 129e6b0603e..d80dc68f2fe 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -110,6 +110,7 @@ class Message(models.Model): ('email', 'Email'), ('comment', 'Comment'), ('notification', 'System notification'), + ('auto_comment', 'Automated Targeted Notification'), ('user_notification', 'User Specific Notification')], 'Type', required=True, default='email', help="Message type: email for email message, notification for system " diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 3de79540e91..ac1d0023ab1 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -670,6 +670,7 @@ class MailThread(models.AbstractModel): continue composition_mode = post_kwargs.pop('composition_mode', default_composition_mode) + post_kwargs.setdefault('message_type', 'auto_comment') if composition_mode == 'mass_mail': cleaned_self.message_mail_with_source(template, **post_kwargs) else: @@ -1646,17 +1647,24 @@ class MailThread(models.AbstractModel): stored_date = datetime.datetime.now() msg_dict['date'] = stored_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) - parent_message = self._get_parent_message(msg_dict) - if parent_message: - msg_dict['parent_id'] = parent_message.id - msg_dict['is_internal'] = bool(parent_message.subtype_id and parent_message.subtype_id.internal) - + msg_dict.update(self._message_parse_extract_from_parent(self._get_parent_message(msg_dict))) msg_dict['is_bounce'] = self._message_parse_is_bounce(message, msg_dict) msg_dict.update(self._message_parse_extract_payload(message, msg_dict, save_original=save_original)) if msg_dict['is_bounce']: msg_dict.update(self._message_parse_extract_bounce(message, msg_dict)) return msg_dict + def _message_parse_extract_from_parent(self, parent_message): + """Derive message values from the parent.""" + if parent_message: + parent_is_internal = bool(parent_message.subtype_id and parent_message.subtype_id.internal) + parent_is_auto_comment = parent_message.message_type == 'auto_comment' + return { + 'parent_id': parent_message.id, + 'is_internal': parent_is_internal and not parent_is_auto_comment + } + return {} + def _get_bounced_message_data(self, message, message_dict): """Find the original and the bounced email references based on an incoming email. diff --git a/addons/mail/static/src/core/message_model.js b/addons/mail/static/src/core/message_model.js index 8183f873e20..287db295303 100644 --- a/addons/mail/static/src/core/message_model.js +++ b/addons/mail/static/src/core/message_model.js @@ -118,6 +118,10 @@ export class Message { return this.datetime.toLocaleString(DateTime.DATETIME_SHORT); } + get isAutomatedMessage() { + return this.type === "auto_comment"; + } + get isSelfMentioned() { return this.recipients.some((recipient) => recipient === this._store.self); } diff --git a/addons/mail/static/src/core_ui/message.js b/addons/mail/static/src/core_ui/message.js index aa9b7b86d30..fe360529f6b 100644 --- a/addons/mail/static/src/core_ui/message.js +++ b/addons/mail/static/src/core_ui/message.js @@ -190,6 +190,9 @@ export class Message extends Component { if (this.props.message.type === "notification") { return _t("System notification"); } + if (this.props.message.type === "auto_comment") { + return _t("Automated message"); + } if (!this.props.message.isDiscussion && this.props.message.type !== "user_notification") { return _t("Note"); } diff --git a/addons/mail/static/src/core_ui/message.xml b/addons/mail/static/src/core_ui/message.xml index 590ac0758aa..a81d71b6644 100644 --- a/addons/mail/static/src/core_ui/message.xml +++ b/addons/mail/static/src/core_ui/message.xml @@ -132,9 +132,9 @@ 'position-absolute top-0': !env.inDiscussApp, 'start-0 ms-3': isAlignedRight, 'end-0 me-3': env.inChatWindow and !isAlignedRight or env.inChatter, - 'mt-n4': env.inChatter and (message.isDiscussion or message.isNotification), - 'mt-n5': env.inChatter and !(message.isDiscussion or message.isNotification), - 'mt-2': env.inDiscussApp and (message.isDiscussion or message.isNotification), + 'mt-n4': env.inChatter and (message.isDiscussion or message.isNotification or message.isAutomatedMessage), + 'mt-n5': env.inChatter and !(message.isDiscussion or message.isNotification or message.isAutomatedMessage), + 'mt-2': env.inDiscussApp and (message.isDiscussion or message.isNotification or message.isAutomatedMessage), 'mt-n3': env.inChatWindow, 'ms-2': env.inDiscussApp, 'invisible': !isActive, @@ -142,7 +142,7 @@ }" >
diff --git a/addons/mail/static/src/core_ui/message_reactions.xml b/addons/mail/static/src/core_ui/message_reactions.xml index 322bd70b490..261a09a3f83 100644 --- a/addons/mail/static/src/core_ui/message_reactions.xml +++ b/addons/mail/static/src/core_ui/message_reactions.xml @@ -4,9 +4,9 @@
+ t-attf-class="{{ (props.message.isDiscussion or props.message.isAutomatedMessage) ? 'mt-n2' : 'mt-1' }}">