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: '
', + 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 = {