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(); + }); +}); + }); });