[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>
This commit is contained in:
Alexandre Kühn
2019-08-30 15:18:05 +00:00
parent 3a52b22b50
commit ad03cac07a
2 changed files with 87 additions and 1 deletions
@@ -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();
}
},
@@ -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);