diff --git a/addons/mail/static/src/js/services/chat_manager.js b/addons/mail/static/src/js/services/chat_manager.js index 8a90fc57482..3e123421886 100644 --- a/addons/mail/static/src/js/services/chat_manager.js +++ b/addons/mail/static/src/js/services/chat_manager.js @@ -1063,7 +1063,7 @@ var ChatManager = AbstractService.extend({ } else if (options.domain && options.domain !== []) { this._addToCache(msg, options.domain); } else if (data.moderation_status === 'accepted') { - msg.channel_ids = data.channel_ids; + msg.channel_ids = _.uniq(data.channel_ids.concat(msg.channel_ids)); msg.needsModeration = false; if (msg.isModerator) { this.moderationCounter--; diff --git a/addons/mail/static/tests/systray_tests.js b/addons/mail/static/tests/systray_tests.js index 0854c43b743..3c4252d6ea5 100644 --- a/addons/mail/static/tests/systray_tests.js +++ b/addons/mail/static/tests/systray_tests.js @@ -372,4 +372,53 @@ QUnit.test("messaging menu widget: messaging menu with 1 message", function ( as messagingMenu.destroy(); }); -}); \ No newline at end of file +QUnit.test("messaging menu widget: no crash on open after receiving a needaction channel message (moderation accepted)", function (assert) { + assert.expect(1); + + var bus = new Bus(); + var CHANNEL_ID = 1; + var PARTNER_ID = 3; + + var messagingMenu = new systray.MessagingMenu(); + testUtils.addMockEnvironment(messagingMenu, { + data: this.data, + services: [ChatManager, createBusService(bus)], + session: { partner_id: PARTNER_ID }, + }); + messagingMenu.appendTo($('#qunit-fixture')); + + // Simulate receiving needaction and channel notifications of a message + // that is 'accepted'. + // Note that we use a different message data object in each notification: + // If we make some changes on one of the object, we should not have changed + // the other object too (as these objects come from two different JSON + // objects from the server). + // For instance, if the 'ir.needaction' notification handling procedure adds + // an item in `channel_ids`, we should not have this item in the + // 'mail.channel' notification. + var messageData1 = { + author_id: [42, "Someone"], + body: "

test

", + channel_ids: [CHANNEL_ID], + moderation_status: 'accepted', + needaction_partner_ids: [PARTNER_ID], + }; + var messageData2 = JSON.parse(JSON.stringify(messageData1)); // deep copy + var needactionNotification = [[false, 'ir.needaction', PARTNER_ID], messageData1]; + var channelNotification = [[false, 'mail.channel', CHANNEL_ID], messageData2]; + bus.trigger('notification', [needactionNotification, channelNotification]); + + // Open the messaging menu + var hasCrashed = false; + try { + messagingMenu.$('.dropdown-toggle').click(); + } catch (err) { + hasCrashed = true; + } + assert.notOk(hasCrashed, + "should not have crashed when opening the messaging menu" + + "after receiving a needaction channel message"); + messagingMenu.destroy(); +}); + +});