From f0346e36a88ca315ff177f1ab3eeb196b06c00c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Sat, 11 Aug 2018 22:44:11 +0200 Subject: [PATCH] [FIX] mail: do not increment unread counter on self-author new messages --- .../js/models/threads/searchable_thread.js | 2 +- .../mail/static/tests/thread_window_tests.js | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/models/threads/searchable_thread.js b/addons/mail/static/src/js/models/threads/searchable_thread.js index 7e4fcedd00a..19c35ec6373 100644 --- a/addons/mail/static/src/js/models/threads/searchable_thread.js +++ b/addons/mail/static/src/js/models/threads/searchable_thread.js @@ -130,7 +130,7 @@ var SearchableThread = Thread.extend({ if (cache.messages[index] !== message) { cache.messages.splice(index, 0, message); } - if (options.incrementUnread) { + if (!message.isMyselfAuthor() && options.incrementUnread) { this._incrementUnreadCounter(); } }, diff --git a/addons/mail/static/tests/thread_window_tests.js b/addons/mail/static/tests/thread_window_tests.js index d8faa8d6a37..6ed3481bad7 100644 --- a/addons/mail/static/tests/thread_window_tests.js +++ b/addons/mail/static/tests/thread_window_tests.js @@ -154,5 +154,60 @@ QUnit.module('mail', { }, 0); }); + QUnit.test('do not increase unread counter when receiving message with myself as author', function (assert) { + assert.expect(4 + this.BEFORE_EACH_ASSERTIONS_NUM); + + var generalChannelID = 1; + var myselfPartnerID = 44; + + this.data.initMessaging = { + channel_slots: { + channel_channel: [{ + id: generalChannelID, + channel_type: 'channel', + name: "general", + }], + }, + }; + + var parent = this.createParent({ + data: this.data, + services: this.services, + session: { partner_id: myselfPartnerID } + }); + + // get channel instance to link to thread window + var channel = parent.call('mail_service', 'getChannel', 1); + channel.detach(); + + var threadWindowHeaderText = $('.o_thread_window_header').text().replace(/\s/g, ""); + + assert.strictEqual(threadWindowHeaderText, "#general", + "thread window header text should not have any unread counter initially"); + assert.strictEqual(channel.getUnreadCounter(), 0, + "thread should have unread counter to 0 initially"); + + // simulate receiving message from myself + var messageData = { + author_id: [myselfPartnerID, "Myself"], + body: "

Test message

", + id: 2, + model: 'mail.channel', + res_id: 1, + channel_ids: [1], + }; + var notification = [[false, 'mail.channel', generalChannelID], messageData]; + parent.call('bus_service', 'trigger', 'notification', [notification]); + + threadWindowHeaderText = $('.o_thread_window_header').text().replace(/\s/g, ""); + + assert.strictEqual(threadWindowHeaderText, "#general", + "thread window header text should not have any unread counter after receiving my message"); + assert.strictEqual(channel.getUnreadCounter(), 0, + "thread should not have incremented its unread counter after receiving my message"); + + parent.destroy(); + }); + }); });