From 614f9f84d7da281b0feacc39a612c19193f3a4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Sat, 11 Aug 2018 21:09:58 +0200 Subject: [PATCH] [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. --- .../services/mail_document_thread_manager.js | 8 ++- 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: '
' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '
', + 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 = {