diff options
| author | Alexandre Kühn <aku@odoo.com> | 2019-08-30 15:18:04 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2019-08-30 15:18:05 +0000 |
| commit | ad03cac07a4ee8dea36d5d5db9ebcedf08803f99 (patch) | |
| tree | 18a03be6123b9eedcb93155b6c8fcc2f0e67b4fe | |
| parent | 3a52b22b503f5a9b42be779a0a92ecd39721363b (diff) | |
[FIX] mail: channel notification messages are never marked as unread
When a user either joins and leaves a channel, it posts a message of
type 'notification' with either action as content.
Before this commit, such messages above were incrementing the unread
counter of the channel. As a result, the messaging menu was showing
this channel as unread with this message.
Messages of type 'notification' should never increment the unread
counter of channel.
This commit fixes the issue by preventing new messages of type
'notification' to increment the unread counter of a conversation.
This should also prevent increasing the counter of the messaging
menu, in addition to highlighting this channel as unread from the
messaging menu.
Task-Id 2059515
closes odoo/odoo#36293
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
| -rw-r--r-- | addons/mail/static/src/js/models/threads/searchable_thread.js | 6 | ||||
| -rw-r--r-- | addons/mail/static/tests/systray/systray_messaging_menu_tests.js | 82 |
2 files changed, 87 insertions, 1 deletions
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 511bc6348c8..2b9d64b2597 100644 --- a/addons/mail/static/src/js/models/threads/searchable_thread.js +++ b/addons/mail/static/src/js/models/threads/searchable_thread.js @@ -148,7 +148,11 @@ var SearchableThread = Thread.extend({ if (cache.messages[index] !== message) { cache.messages.splice(index, 0, message); } - if (!message.isMyselfAuthor() && options.incrementUnread) { + if ( + !message.isMyselfAuthor() && + options.incrementUnread && + message.getType() !== 'notification' + ) { this._incrementUnreadCounter(); } }, diff --git a/addons/mail/static/tests/systray/systray_messaging_menu_tests.js b/addons/mail/static/tests/systray/systray_messaging_menu_tests.js index dc0b3515c7d..68c37fad438 100644 --- a/addons/mail/static/tests/systray/systray_messaging_menu_tests.js +++ b/addons/mail/static/tests/systray/systray_messaging_menu_tests.js @@ -427,6 +427,88 @@ QUnit.test('update messaging preview on receiving a new message in channel previ messagingMenu.destroy(); }); +QUnit.test('new message of type "notification" are not considered as unread messages', async function (assert) { + assert.expect(8); + + const messagingMenu = new MessagingMenu(); + testUtils.mock.addMockEnvironment(messagingMenu, { + data: this.data, + services: this.services, + }); + await messagingMenu.appendTo($('#qunit-fixture')); + // open messaging menu + await testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsOnce( + messagingMenu, + '.o_mail_preview', + "should display a single channel preview"); + assert.strictEqual( + messagingMenu + .$('.o_preview_name') + .text() + .trim(), + "general", + "should display channel preview of 'general' channel"); + assert.strictEqual( + messagingMenu + .$('.o_preview_counter') + .text() + .trim(), + "", + "should have unread counter of 0 for 'general' channel (no unread messages)"); + assert.strictEqual( + messagingMenu + .$('.o_last_message_preview') + .text() + .replace(/\s/g, ""), + "Me:test", + "should display author name and inline body of currently last message in the channel"); + // close messaging menu + await testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + + // simulate receiving a new message on the channel 'general' (id 1) + // of type 'notification' + const data = { + id: 100, + author_id: [42, "Someone"], + body: "<p>Left #general</p>", + channel_ids: [1], + message_type: 'notification', + }; + const notification = [[false, 'mail.channel', 1], data]; + messagingMenu.call('bus_service', 'trigger', 'notification', [notification]); + await testUtils.nextTick(); + // open messaging menu + await testUtils.dom.click(messagingMenu.$('.dropdown-toggle')); + assert.containsOnce( + messagingMenu, + '.o_mail_preview', + "should still display a single channel preview"); + assert.strictEqual( + messagingMenu + .$('.o_preview_name') + .text() + .trim(), + "general", + "should still display channel preview of 'general' channel"); + assert.strictEqual( + messagingMenu + .$('.o_preview_counter') + .text() + .trim(), + "", + "should still have unread counter of 0 for 'general' channel (no unread messages)"); + assert.strictEqual( + messagingMenu + .$('.o_last_message_preview') + .text() + .replace(/\s/g, ""), + "Someone:Left#general", + "should display author name and inline body of notification message (last message of channel)"); + + messagingMenu.destroy(); +}); + QUnit.test('preview of inbox message not linked to document + mark as read', async function (assert) { assert.expect(17); |
