From 0fb43cf1336ce00800163308a67809889057371d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Tue, 19 Feb 2019 09:24:40 +0000 Subject: [PATCH] [FIX] mail: no traceback on receiving seen notification Before this commit, when we post a message and someone has received it, there could be a traceback. Steps to reproduce: 1. Two users are logged in. 2. On one user: - open any app except Discuss - From systray messaging menu, click on "New messages" - Open Discuss - Post a message in a direct chat with other User. > traceback `Cannot read property 'getID' of null` closes odoo/odoo#31228 --- .../src/js/thread_windows/thread_window.js | 3 ++ .../systray/systray_messaging_menu_tests.js | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/addons/mail/static/src/js/thread_windows/thread_window.js b/addons/mail/static/src/js/thread_windows/thread_window.js index 331228c91c8..d7f6acbda5f 100644 --- a/addons/mail/static/src/js/thread_windows/thread_window.js +++ b/addons/mail/static/src/js/thread_windows/thread_window.js @@ -377,6 +377,9 @@ var ThreadWindow = AbstractThreadWindow.extend({ * @param {integer} channelID */ _onUpdateChannel: function (channelID) { + if (!this.hasThread()) { + return; + } if (this._thread.getID() !== channelID) { return; } 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 18a8838be7e..00abb2d0503 100644 --- a/addons/mail/static/tests/systray/systray_messaging_menu_tests.js +++ b/addons/mail/static/tests/systray/systray_messaging_menu_tests.js @@ -634,6 +634,50 @@ QUnit.test("messaging menu widget: channel seen notification", function (assert) messagingMenu.destroy(); }); +QUnit.test("messaging menu widget: no traceback when receiving channel_fetched notification with blank thread window", function (assert) { + assert.expect(3); + + this.data.initMessaging.channel_slots = { + channel_direct_message: [{ + id: 1, + channel_type: "chat", + direct_partner: [{ id: 2, name: 'Someone', im_status: '' }], + name: 'DM', + message_unread_counter: 1, + }], + }; + + var messagingMenu = new MessagingMenu(); + testUtils.mock.addMockEnvironment(messagingMenu, { + services: this.services, + data: this.data, + session: { partner_id: 3 }, + }); + + messagingMenu.appendTo($('#qunit-fixture')); + messagingMenu.$('.dropdown-toggle').click(); + assert.containsOnce(messagingMenu, '.o_new_message', + "should have button to open blank thread window"); + + testUtils.dom.click(messagingMenu.$('.o_new_message')); + var $threadWindow = $('.o_thread_window'); + assert.strictEqual($threadWindow.length, 1, "should have an open thread window"); + assert.ok($threadWindow.hasClass('o_thread_less'), "should be a blank thread window"); + + // Simulate received channel fetched notification + var message = { + info: 'channel_fetched', + last_message_id: 1, + partner_id: 2, + }; + var notifications = [ + [['myDB', 'mail.channel', 1], message] + ]; + messagingMenu.call('bus_service', 'trigger', 'notification', notifications); + + messagingMenu.destroy(); +}); + QUnit.test("messaging menu widget: preview with no message should be undated", function ( assert ) { assert.expect(2);