[FIX] mail: use a placeholder when replying to empty message

Before the PR, when replying to an empty (only attachment) nothing was display
in the message reply preview. This PR introduce a placeholder to handle this
case.

Also taking to opportunity to add missing translations.

task-2664815

closes odoo/odoo#81996

X-original-commit: 60f68512fdc9ebfb2d9331790be5884a86cce67b
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Didier (did)
2022-01-03 13:22:42 +00:00
parent f6240e3b9c
commit c718fce536
4 changed files with 89 additions and 13 deletions
+13
View File
@@ -1438,6 +1438,13 @@ msgstr ""
msgid "Click on your message"
msgstr ""
#. module: mail
#. openerp-web
#: code:addons/mail/static/src/components/message_in_reply_to_view/message_in_reply_to_view.xml:0
#, python-format
msgid "Click to see the attachments"
msgstr ""
#. module: mail
#. openerp-web
#: code:addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml:0
@@ -4793,6 +4800,12 @@ msgstr ""
msgid "Only logged notes can have their content updated on model '%s'"
msgstr ""
#. module: mail
#: code:addons/mail/models/mail_thread.py:0
#, python-format
msgid "Only messages type comment can have their content updated"
msgstr ""
#. module: mail
#: code:addons/mail/models/mail_channel.py:0
#, python-format
@@ -5,7 +5,15 @@
<t t-if="messageInReplyToView">
<t t-if="!messageInReplyToView.messageView.message.parentMessage.isEmpty">
<b class="o_MessageInReplyToView_author text-muted ml-2">@<t t-esc="messageInReplyToView.messageView.message.parentMessage.authorName"/></b>
<span class="o_MessageInReplyToView_body ml-1" t-raw="messageInReplyToView.messageView.message.parentMessage.prettyBody" t-on-click="messageInReplyToView.onClickReply"/>
<span class="o_MessageInReplyToView_body ml-1" t-on-click="messageInReplyToView.onClickReply">
<t t-if="messageInReplyToView.hasBodyBackLink">
<t t-raw="messageInReplyToView.messageView.message.parentMessage.prettyBody"/>
</t>
<t t-if="messageInReplyToView.hasAttachmentBackLink">
<span class="font-italic mr-2">Click to see the attachments</span>
<i class="fa fa-image"/>
</t>
</span>
</t>
<t t-if="messageInReplyToView.messageView.message.parentMessage.isEmpty">
<i class="o_MessageInReplyToView_deletedMessage text-muted ml-2">Original message was deleted</i>
@@ -367,6 +367,13 @@ registerModel({
_computeFailureNotifications() {
return replace(this.notifications.filter(notifications => notifications.isFailure));
},
/**
* @private
* @returns {boolean}
*/
_computeHasAttachments() {
return this.attachments.length > 0;
},
/**
* @returns {boolean}
*/
@@ -388,6 +395,21 @@ registerModel({
this.messaging.currentGuest === this.guestAuthor
);
},
/**
* @private
* @returns {boolean}
*/
_computeIsBodyEmpty() {
return (
!this.body ||
[
'',
'<p></p>',
'<p><br></p>',
'<p><br/></p>',
].includes(this.body.replace(/\s/g, ''))
);
},
/**
* @private
* @returns {boolean}
@@ -417,18 +439,9 @@ registerModel({
* @returns {boolean}
*/
_computeIsEmpty() {
const isBodyEmpty = (
!this.body ||
[
'',
'<p></p>',
'<p><br></p>',
'<p><br/></p>',
].includes(this.body.replace(/\s/g, ''))
);
return (
isBodyEmpty &&
this.attachments.length === 0 &&
this.isBodyEmpty &&
!this.hasAttachments &&
this.tracking_value_ids.length === 0 &&
!this.subtype_description
);
@@ -587,6 +600,12 @@ registerModel({
guestAuthor: many2one('Guest', {
inverse: 'authoredMessages',
}),
/**
* States whether the message has some attachments.
*/
hasAttachments: attr({
compute: '_computeHasAttachments',
}),
/**
* Determines whether the message has a reaction icon.
*/
@@ -601,6 +620,14 @@ registerModel({
compute: '_computeIsCurrentUserOrGuestAuthor',
default: false,
}),
/**
* States if the body field is empty, regardless of editor default
* html content. To determine if a message is fully empty, use
* `isEmpty`.
*/
isBodyEmpty: attr({
compute: '_computeIsBodyEmpty',
}),
/**
* States whether `body` and `subtype_description` contain similar
* values.
@@ -1,7 +1,7 @@
/** @odoo-module **/
import { registerModel } from '@mail/model/model_core';
import { one2one } from '@mail/model/model_field';
import { attr, one2one } from '@mail/model/model_field';
import { replace } from '@mail/model/model_field_command';
import { markEventHandled } from '@mail/utils/utils';
@@ -35,8 +35,36 @@ registerModel({
}
threadView.addComponentHint('highlight-reply', parentMessageView);
},
/**
* @private
* @returns {boolean}
*/
_computeHasAttachmentBackLink() {
const parentMessage = this.messageView.message.parentMessage;
return parentMessage.isBodyEmpty && parentMessage.hasAttachments;
},
/**
* @private
* @returns {boolean}
*/
_computeHasBodyBackLink() {
return !this.messageView.message.parentMessage.isBodyEmpty;
},
},
fields: {
/**
* Determines if the reply has a back link to an attachment only
* message.
*/
hasAttachmentBackLink: attr({
compute: '_computeHasAttachmentBackLink',
}),
/**
* Determines if the reply has a back link to a non-empty body.
*/
hasBodyBackLink: attr({
compute: '_computeHasBodyBackLink',
}),
messageView: one2one('MessageView', {
inverse: 'messageInReplyToView',
readonly: true,