From 6f7a04be0bbe870a33e85e3ff96f583206c30463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 26 Nov 2018 11:54:32 +0000 Subject: [PATCH] [FIX] mail: reply message from inbox Revision on https://github.com/odoo/odoo/commit/cd34f6de727d5b3858420cff3c9d3c5995c4e75c Before the commit above, it was possible to reply to a message from Inbox. Those messages were linked to a document, and replying to any of them put a response in the related document. This feature has been broken since the commit above: the reply icon was only shown on messages linked to a channel, instead of message linked to a document. Also, it was erroneously prompting that the message was sent to the channel, even though it was not the case. This commit fixes the issue by toggling the visibility of the reply icon, so that it is shown only for messages that come from a document. Also, since posting a message requires a thread, this commit added the possibility to post a message from a mailbox, which instead posts the message to the related document thread. Task-ID 1912647 closes odoo/odoo#29028 --- addons/mail/static/src/js/discuss.js | 6 +- .../static/src/js/models/threads/mailbox.js | 21 +++++ addons/mail/static/src/xml/thread.xml | 2 +- addons/mail/static/tests/discuss_tests.js | 79 +++++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/js/discuss.js b/addons/mail/static/src/js/discuss.js index e93adeaae30..2cb9fe749d7 100644 --- a/addons/mail/static/src/js/discuss.js +++ b/addons/mail/static/src/js/discuss.js @@ -1321,12 +1321,16 @@ var Discuss = AbstractAction.extend(ControlPanelMixin, { */ _onPostMessage: function (messageData) { var self = this; + var options = {}; if (this._selectedMessage) { messageData.subtype = this._selectedMessage.isNote() ? 'mail.mt_note': 'mail.mt_comment'; messageData.subtype_id = false; messageData.message_type = 'comment'; + + options.documentID = this._selectedMessage.getDocumentID(); + options.documentModel = this._selectedMessage.getDocumentModel(); } - this._thread.postMessage(messageData) + this._thread.postMessage(messageData, options) .then(function () { if (self._selectedMessage) { self._renderSnackbar('mail.discuss.MessageSentSnackbar', { diff --git a/addons/mail/static/src/js/models/threads/mailbox.js b/addons/mail/static/src/js/models/threads/mailbox.js index 82d65bdd6cc..263072f575e 100644 --- a/addons/mail/static/src/js/models/threads/mailbox.js +++ b/addons/mail/static/src/js/models/threads/mailbox.js @@ -189,6 +189,27 @@ var Mailbox = SearchableThread.extend({ throw (_.str(_t("Missing domain for mailbox with ID '%s'"), this._id)); } }, + /** + * Post a message from inbox. This is used when using the 'reply' feature + * on a message that is linked to a document thread. + * + * @override + * @private + * @param {Object} messageData + * @param {Object} options + * @param {integer} options.documentID + * @param {string} options.documentModel + * @returns {$.Promise} + */ + _postMessage: function (messageData, options) { + var documentThread = this.call( + 'mail_service', + 'getDocumentThread', + options.documentModel, + options.documentID + ); + return documentThread.postMessage(messageData); + }, }); return Mailbox; diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml index e5db4a72524..f28e071b2f3 100644 --- a/addons/mail/static/src/xml/thread.xml +++ b/addons/mail/static/src/xml/thread.xml @@ -338,7 +338,7 @@ - test 1

', + id: 1, + needaction: true, + needaction_partner_ids: [3], + res_id: 100, + model: 'some.document', + record_name: 'SomeDocument', + }]; + this.data.initMessaging = { + needaction_inbox_counter: 1, + }; + + createDiscuss({ + id: 1, + context: {}, + params: {}, + data: this.data, + services: this.services, + session: { partner_id: 3 }, + mockRPC: function (route, args) { + if (args.method === 'message_post') { + assert.step(args.method); + assert.strictEqual(args.model, 'some.document', + "should post message to correct document model"); + assert.strictEqual(args.args[0], 100, + "should post message to correct document ID"); + + self.data['mail.message'].records.push({ + author_id: [3, 'Me'], + body: args.kwargs.body, + id: 2, + res_id: 100, + model: 'some.document', + record_name: 'SomeDocument', + }); + return $.when(2); + } + return this._super.apply(this, arguments); + }, + }) + .then(function (discuss) { + assert.strictEqual(discuss.$('.o_mail_discuss_item.o_active').data('thread-id'), + 'mailbox_inbox', + "Inbox should be selected by default"); + assert.containsOnce(discuss, '.o_thread_message', + "should display a single message in inbox"); + assert.strictEqual(discuss.$('.o_thread_message').data('message-id'), 1, + "message should be linked to correct message"); + assert.containsOnce(discuss.$('.o_thread_message'), '.o_thread_message_reply', + "should display the reply icon for message linked to a document"); + + testUtils.dom.click(discuss.$('.o_thread_message_reply')); + var $composer = discuss.$('.o_thread_composer_extended'); + assert.isVisible($composer, + "extended composer should become visible"); + assert.strictEqual($composer.find('.o_composer_subject input').val(), + 'Re: SomeDocument', + "composer should have copied document name as subject of message"); + + var $textarea = $composer.find('.o_composer_input textarea').first(); + testUtils.fields.editInput($textarea, 'someContent'); + assert.containsOnce($composer, '.o_composer_button_send', + "should have button to send reply message"); + testUtils.dom.click($composer.find('.o_composer_button_send')); + + assert.verifySteps(['message_post']); + + discuss.destroy(); + done(); + }); +}); + }); });