From a13db188f3c2e26ddf45b3d12d64615bfe876171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Tue, 20 Nov 2018 10:26:06 +0000 Subject: [PATCH] [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 --- .../src/js/models/threads/abstract_thread.js | 2 +- .../systray/systray_messaging_menu_tests.js | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/models/threads/abstract_thread.js b/addons/mail/static/src/js/models/threads/abstract_thread.js index 03bddd7d945..829f54581da 100644 --- a/addons/mail/static/src/js/models/threads/abstract_thread.js +++ b/addons/mail/static/src/js/models/threads/abstract_thread.js @@ -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(); }, /** 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 1b608f5c37b..2df0f7ac522 100644 --- a/addons/mail/static/tests/systray/systray_messaging_menu_tests.js +++ b/addons/mail/static/tests/systray/systray_messaging_menu_tests.js @@ -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(); +}); + }); });