summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2021-01-26 14:03:11 +0000
committerSébastien Theys <seb@odoo.com>2021-01-26 14:03:11 +0000
commit8668b3ff8da395738c030e45ff1787efd8b45df3 (patch)
tree52f7b732363ffc71afec22afec4ffb4b486bf22d /addons/mail/static/src/models
parent63e36a9254c20726b57160b0bd08bc3aa292a063 (diff)
[FIX] mail: avoid hiding non-text messages that are not empty
task-2447695 closes odoo/odoo#65061 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models')
-rw-r--r--addons/mail/static/src/models/message/message.js26
-rw-r--r--addons/mail/static/src/models/message/message_tests.js70
2 files changed, 95 insertions, 1 deletions
diff --git a/addons/mail/static/src/models/message/message.js b/addons/mail/static/src/models/message/message.js
index e823be99b78..627a8a281f7 100644
--- a/addons/mail/static/src/models/message/message.js
+++ b/addons/mail/static/src/models/message/message.js
@@ -420,11 +420,34 @@ function factory(dependencies) {
}
/**
+ * The method does not attempt to cover all possible cases of empty
+ * messages, but mostly those that happen with a standard flow. Indeed
+ * it is preferable to be defensive and show an empty message sometimes
+ * instead of hiding a non-empty message.
+ *
+ * The main use case for when a message should become empty is for a
+ * message posted with only an attachment (no body) and then the
+ * attachment is deleted.
+ *
+ * The main use case for being defensive with the check is when
+ * receiving a message that has no textual content but has other
+ * meaningful HTML tags (eg. just an <img/>).
+ *
* @private
+ * @returns {boolean}
*/
_computeIsEmpty() {
+ const isBodyEmpty = (
+ !this.body ||
+ [
+ '',
+ '<p></p>',
+ '<p><br></p>',
+ '<p><br/></p>',
+ ].includes(this.body.replace(/\s/g, ''))
+ );
return (
- (!this.body || htmlToTextContentInline(this.body) === '') &&
+ isBodyEmpty &&
this.attachments.length === 0 &&
this.tracking_value_ids.length === 0 &&
!this.subtype_description
@@ -600,6 +623,7 @@ function factory(dependencies) {
dependencies: [
'attachments',
'body',
+ 'subtype_description',
'tracking_value_ids',
],
}),
diff --git a/addons/mail/static/src/models/message/message_tests.js b/addons/mail/static/src/models/message/message_tests.js
index bc3cf58ef46..054e82049ac 100644
--- a/addons/mail/static/src/models/message/message_tests.js
+++ b/addons/mail/static/src/models/message/message_tests.js
@@ -110,6 +110,76 @@ QUnit.test('create', async function (assert) {
assert.strictEqual(partner.id, 5);
});
+QUnit.test('message without body should be considered empty', async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test('message with body "" should be considered empty', async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "", id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test('message with body "<p></p>" should be considered empty', async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "<p></p>", id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test('message with body "<p><br></p>" should be considered empty', async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "<p><br></p>", id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test('message with body "<p><br/></p>" should be considered empty', async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "<p><br/></p>", id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test(String.raw`message with body "<p>\n</p>" should be considered empty`, async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "<p>\n</p>", id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test(String.raw`message with body "<p>\r\n\r\n</p>" should be considered empty`, async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "<p>\r\n\r\n</p>", id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test('message with body "<p> </p> " should be considered empty', async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "<p> </p> ", id: 11 });
+ assert.ok(message.isEmpty);
+});
+
+QUnit.test(`message with body "<img src=''>" should not be considered empty`, async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "<img src=''>", id: 11 });
+ assert.notOk(message.isEmpty);
+});
+
+QUnit.test('message with body "test" should not be considered empty', async function (assert) {
+ assert.expect(1);
+ await this.start();
+ const message = this.env.models['mail.message'].create({ body: "test", id: 11 });
+ assert.notOk(message.isEmpty);
+});
+
});
});
});