From bc4e06106daee49bc102c6eb6778842b38baccd7 Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Tue, 13 Oct 2020 08:21:58 +0000 Subject: [PATCH] [FIX] mail: mail not sent because partner not find in chatter + unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue - Install "Project" module - Go to the chatter of any Task - Log the following message (by selecting the partner) then send: "test@test.com @marc Demo " Message is not sent. Cause When parsing the content, the match result is "@test.com\n@Marc Demo" due to no space between the two mentions Solution Add space after line break (only when parsing selection). In this case, it will match with 2 mentions instead: "@test.com\n" and "@marc Demo " For _generateMentionsLinks step, add a space after '
', it will match 2 mentions but we remove the ones that end with '
'. This last fix is to avoid having a non-mention string containing '
' (for example), and therefore not having them escaped in final message content. opw-2322577 closes odoo/odoo#60128 X-original-commit: 8f12c025e05e5a3a7cf3c5fa8c2696ec99e2fa07 Signed-off-by: Alexandre Kühn (aku) --- .../thread_view/thread_view_tests.js | 43 +++++++++++++++++++ .../static/src/models/composer/composer.js | 6 ++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/components/thread_view/thread_view_tests.js b/addons/mail/static/src/components/thread_view/thread_view_tests.js index 5230f252e03..69039d2e1b8 100644 --- a/addons/mail/static/src/components/thread_view/thread_view_tests.js +++ b/addons/mail/static/src/components/thread_view/thread_view_tests.js @@ -1138,6 +1138,49 @@ QUnit.test('delete all attachments of a message with tracking fields should stil ); }); +QUnit.test('Post a message containing an email address followed by a mention on another line', async function (assert) { + assert.expect(1); + + this.data['mail.channel'].records.push({ id: 11 }); + this.data['res.partner'].records.push({ + id: 25, + email: "testpartner@odoo.com", + name: "TestPartner", + }); + await this.start(); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 11, + model: 'mail.channel' + }); + const threadViewer = this.env.models['mail.thread_viewer'].create({ + hasThreadView: true, + thread: [['link', thread]], + }); + await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true }); + document.querySelector('.o_ComposerTextInput_textarea').focus(); + await afterNextRender(() => document.execCommand('insertText', false, "email@odoo.com\n")); + await afterNextRender(() => { + ["@", "T", "e"].forEach((char)=>{ + document.execCommand('insertText', false, char); + document.querySelector(`.o_ComposerTextInput_textarea`) + .dispatchEvent(new window.KeyboardEvent('keydown')); + document.querySelector(`.o_ComposerTextInput_textarea`) + .dispatchEvent(new window.KeyboardEvent('keyup')); + }) + }); + await afterNextRender(() => { + document.querySelector('.o_ComposerSuggestion').click() + }); + await afterNextRender(() => { + document.querySelector('.o_Composer_buttonSend').click(); + }); + assert.containsOnce( + document.querySelector(`.o_Message_content`), + `.o_mail_redirect[data-oe-id="25"][data-oe-model="res.partner"]:contains("@TestPartner")`, + "Conversation should have a message that has been posted, which contains partner mention" + ); +}); + }); }); }); diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js index 3bb12b29433..45e68546813 100644 --- a/addons/mail/static/src/models/composer/composer.js +++ b/addons/mail/static/src/models/composer/composer.js @@ -486,7 +486,7 @@ function factory(dependencies) { * @returns {mail.partner[]} */ _computeMentionedPartners() { - const inputMentions = this.textInputContent.match( + const inputMentions = this.textInputContent.replace('\n', "\n ").match( new RegExp("@[^ ]+(?= | |$)", 'g') ) || []; const unmentionedPartners = []; @@ -556,7 +556,9 @@ function factory(dependencies) { if (this.mentionedPartners.length === 0 && this.mentionedChannels.length === 0) { return body; } - const inputMentions = body.match(new RegExp("(@|#)" + '[^ ]+(?= | |$)', 'g')); + const inputMentions = body.replace("
", "
") + .match(new RegExp("(@|#)" + '[^ ]+(?= | |$)', 'g')) + .filter(match => !match.endsWith("
")); const substrings = []; let startIndex = 0; for (const match of inputMentions) {