[FIX] mail: notify when resetting unread counter of thread

Before this commit, we had the following issue:

1. Open two tabs A & B.
2. Receive a message from a channel in tab A.
3. Mark it as read in tab A by clicking on the
   chat window of the channel.

> The unread counter is correct in tab A: no
  unread messages on this channel, and the
  messaging menu counter has been updated.
> The unread counter is not correct in tab B:
  it still has unread messages on this channel,
  and the messaging menu counter has not been
  updated.

The issue was caused by not notifying the updated
unread counter to the widgets when receiving the
'channel_seen' notification from the longpoll.
It was working in tab A because this is were we made
the action, so that it already marked messages as
read without waiting for the longpoll response.
However, Tab B has to wait for the longpoll response
to update the unread counter. It was updating the
counter, but it was not notifying the widgets.

This commit fixes the issue by letting the widgets
know when the unread counter has been reset.

Task-ID 1911239

closes odoo/odoo#28833
This commit is contained in:
Alexandre Kühn
2018-11-20 10:52:26 +00:00
parent 09a2ef2e7c
commit a13db188f3
2 changed files with 40 additions and 1 deletions
@@ -147,6 +147,7 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, {
*/
resetUnreadCounter: function () {
this._unreadCounter = 0;
this._warnUpdatedUnreadCounter();
},
//--------------------------------------------------------------------------
@@ -177,7 +178,6 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, {
*/
_markAsRead: function () {
this.resetUnreadCounter();
this._warnUpdatedUnreadCounter();
return $.when();
},
/**
@@ -586,5 +586,44 @@ QUnit.test('grouped preview for needaction messages linked to same document', fu
messagingMenu.destroy();
});
QUnit.test("messaging menu widget: channel seen notification", function ( assert ) {
assert.expect(4);
this.data.initMessaging.channel_slots.channel_channel[0].message_unread_counter = 1;
var messagingMenu = new MessagingMenu();
testUtils.addMockEnvironment(messagingMenu, {
services: this.services,
data: this.data,
});
messagingMenu.appendTo($('#qunit-fixture'));
messagingMenu.$('.dropdown-toggle').click();
assert.strictEqual(messagingMenu.$('.o_notification_counter').text(), '1',
"should have correct messaging menu counter (1 unread message in channel)");
assert.strictEqual(messagingMenu.$('.o_preview_counter').text().replace(/\s/g, ''),
'(1)',
"should display 1 unread message on general channel preview");
// Simulate received channel seen notification
var message = {
info: 'channel_seen',
id: 1,
last_message_id: 1,
};
var notifications = [
[['myDB', 'res.partner'], message]
];
messagingMenu.call('bus_service', 'trigger', 'notification', notifications);
assert.strictEqual(messagingMenu.$('.o_notification_counter').text(), '0',
"should no longer have a messaging menu counter (no unread message in channel)");
assert.strictEqual(messagingMenu.$('.o_preview_counter').text().replace(/\s/g, ''), '',
"should no longer display unread message on general channel preview");
messagingMenu.destroy();
});
});
});