diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-08-11 21:09:58 +0200 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-08-13 14:17:27 +0200 |
| commit | 614f9f84d7da281b0feacc39a612c19193f3a4d8 (patch) | |
| tree | 24b9336a7b69c8b38fb37614cbc89c61c731829d /addons/mail/static | |
| parent | e0a51edd856b36bfdf1cacb4d7e8d70fad7884fa (diff) | |
[FIX] mail: display new messages on reload for document threads without any name
A document thread is a JS-only entity, which is built from data on
'mail.message' received from the server, or from data of a document.
When we detect a change on the message IDs related to a document thread,
we should update this list on the document thread, so that it knows which
messages haven't be fetched from the server yet.
However, the list of message IDs was not updated on a document thread when
no name could be provided to the document thread, which occurs when there
is no no `display_name` data to determine on the record's name.
In this case, it should update the list of message IDs on this document thread
without altering document name. However, it was neither changing the document
name nor updating the message IDs.
This commit fixes this issue by independently update message IDs and the
document name of a document thread.
Diffstat (limited to 'addons/mail/static')
| -rw-r--r-- | addons/mail/static/src/js/services/mail_document_thread_manager.js | 8 | ||||
| -rw-r--r-- | addons/mail/static/tests/chatter_tests.js | 68 |
2 files changed, 73 insertions, 3 deletions
diff --git a/addons/mail/static/src/js/services/mail_document_thread_manager.js b/addons/mail/static/src/js/services/mail_document_thread_manager.js index 6e4c8fb591c..a98ae317c9d 100644 --- a/addons/mail/static/src/js/services/mail_document_thread_manager.js +++ b/addons/mail/static/src/js/services/mail_document_thread_manager.js @@ -109,12 +109,14 @@ MailManager.include({ }, }); this._threads.push(thread); - } else if (params.name) { + } else { if ('messageIDs' in params) { thread.setMessageIDs(params.messageIDs); } - // document thread may have a change of name - thread.setName(params.name); + if ('name' in params && params.name) { + // document thread may have a change of name + thread.setName(params.name); + } } return thread; }, diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index a46d02132c4..c1d6edd8207 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -1786,6 +1786,74 @@ QUnit.test('chatter: do not duplicate messages on (un)star message', function (a form.destroy(); }); +QUnit.test('chatter: new messages on document without any "display_name"', function (assert) { + assert.expect(5); + + this.data.partner.records[0].message_ids = [1]; + this.data.partner.records[0].display_name = false; + this.data['mail.message'].records = [{ + author_id: [1, "John Doe"], + body: "A message", + date: "2016-12-20 09:35:40", + id: 1, + is_note: false, + is_discussion: true, + is_notification: false, + is_starred: false, + model: 'partner', + res_id: 2, + }]; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + services: this.services, + arch: '<form string="Partners">' + + '<sheet>' + + '<field name="foo"/>' + + '</sheet>' + + '<div class="oe_chatter">' + + '<field name="message_ids" widget="mail_thread" options="{\'display_log_button\': True}"/>' + + '</div>' + + '</form>', + res_id: 2, + session: {}, + }); + + assert.strictEqual(form.$('.o_thread_message').length, 1, + "should have a single message in the chatter"); + assert.strictEqual(form.$('.o_thread_message[data-message-id="1"]').length, 1, + "single message should have ID 1"); + + // Simulate a new message in the chatter + this.data['mail.message'].records.push({ + author_id: [2, "Mister Smith"], + body: "Second message", + date: "2016-12-20 09:35:40", + id: 2, + is_note: false, + is_discussion: true, + is_notification: false, + is_starred: false, + model: 'partner', + res_id: 2, + }); + this.data.partner.records[0].message_ids.push(2); + + form.reload(); + + assert.strictEqual(form.$('.o_thread_message').length, 2, + "should have a two messages in the chatter after reload"); + assert.strictEqual(form.$('.o_thread_message[data-message-id="1"]').length, 1, + "one of the message should have ID 1"); + assert.strictEqual(form.$('.o_thread_message[data-message-id="2"]').length, 1, + "the other message should have ID 2"); + + //cleanup + form.destroy(); +}); + QUnit.module('FieldMany2ManyTagsEmail', { beforeEach: function () { this.data = { |
