diff options
| author | Ipsita Borisagar <ibo@odoo.com> | 2021-02-09 04:48:29 +0000 |
|---|---|---|
| committer | Ipsita Borisagar <ibo@odoo.com> | 2021-02-15 05:11:19 +0000 |
| commit | ff44dbf31a3732a8ebced7ff907fff3b2440afc4 (patch) | |
| tree | e74a602dedaa285b59a30b27a4278f4cf3e84f37 /addons | |
| parent | b13fc817d150f642254c4738cfbd91ac2ecaa65f (diff) | |
[FIX] mail: prevent message separator for new conversations
Before this commit:
When a new conversation is initiated, the 'new messages' separator is displayed.
This looks a bit weird as there is no history of conversation and thus no older
messages from which new messages should be separated.
After this commit:
The 'new messages' separator will not be displayed in new conversations.
LINKS
PR https://github.com/odoo/odoo/pull/65952
Task-2453511
closes odoo/odoo#65952
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js | 54 | ||||
| -rw-r--r-- | addons/mail/static/src/models/thread/thread.js | 3 |
2 files changed, 54 insertions, 3 deletions
diff --git a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js index f3234bc5fc9..4e032e93dfb 100644 --- a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js +++ b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js @@ -2186,7 +2186,7 @@ QUnit.test('chat window does not fetch messages if hidden', async function (asse ); }); -QUnit.test('new message separator is shown in a chat window of a chat on receiving new message', async function (assert) { +QUnit.test('new message separator is shown in a chat window of a chat on receiving new message if there is a history of conversation', async function (assert) { assert.expect(6); this.data['res.partner'].records.push({ id: 10, name: "Demo" }); @@ -2205,6 +2205,12 @@ QUnit.test('new message separator is shown in a chat window of a chat on receivi uuid: 'channel-10-uuid', }, ]; + this.data['mail.message'].records.push({ + body: "not empty", + channel_ids: [10], + model: 'mail.channel', + res_id: 10, + }); await this.start({ mockRPC(route, args) { if (args.method === 'channel_fold') { @@ -2232,10 +2238,11 @@ QUnit.test('new message separator is shown in a chat window of a chat on receivi '.o_ChatWindow', "a chat window should be visible after receiving a new message from a chat" ); - assert.containsOnce( + assert.containsN( document.body, '.o_Message', - "chat window should have a single message (the newly received one)" + 2, + "chat window should have 2 messages" ); assert.containsOnce( document.body, @@ -2248,6 +2255,41 @@ QUnit.test('new message separator is shown in a chat window of a chat on receivi ); }); +QUnit.test('new message separator is not shown in a chat window of a chat on receiving new message if there is no history of conversation', async function (assert) { + assert.expect(1); + + this.data['res.partner'].records.push({ id: 10, name: "Demo" }); + this.data['res.users'].records.push({ + id: 42, + name: "Foreigner user", + partner_id: 10, + }); + this.data['mail.channel'].records = [{ + channel_type: "chat", + id: 10, + members: [this.data.currentPartnerId, 10], + uuid: 'channel-10-uuid', + }]; + await this.start(); + + // simulate receiving a message + await afterNextRender(async () => this.env.services.rpc({ + route: '/mail/chat_post', + params: { + context: { + mockedUserId: 42, + }, + message_content: "hu", + uuid: 'channel-10-uuid', + }, + })); + assert.containsNone( + document.body, + '.o_MessageList_separatorNewMessages', + "should not display 'new messages' separator in the conversation of a chat on receiving new message if there is no history of conversation" + ); +}); + QUnit.test('focusing a chat window of a chat should make new message separator disappear [REQUIRE FOCUS]', async function (assert) { assert.expect(2); @@ -2268,6 +2310,12 @@ QUnit.test('focusing a chat window of a chat should make new message separator d uuid: 'channel-10-uuid', }, ); + this.data['mail.message'].records.push({ + body: "not empty", + channel_ids: [10], + model: 'mail.channel', + res_id: 10, + }); await this.start(); // simulate receiving a message diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index 31339e063f3..4739e59f91e 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -1344,6 +1344,9 @@ function factory(dependencies) { const index = this.orderedMessages.findIndex(message => message.id === this.lastSeenByCurrentPartnerMessageId ); + if (index === -1) { + return [['unlink']]; + } const message = this.orderedMessages[index + 1]; if (!message) { return [['unlink']]; |
