[FIX] mail: no crash on opening messaging menu after receiving a needaction message

Revision on https://github.com/odoo/odoo/commit/299ebb2cdf63de2e3967da0d2f3e7effd239812b
    [IMP] mail: add moderation on channels

The commit above adds moderated channel. When a message is pending moderation,
it is not yet linked to the channel server-side, which is why there is a hack
to set `channel_ids` on the client side so that the message is visible on the
corresponding channel (only for author of message and moderator of channel).

It is only when the message is accepted that this message is linked to the
correct `channel_ids`. The server provides the updated list of channels that
this message is linked to, but it misses static channels that only make sense
on the client-side, such as "Inbox" or "Starred".

This commit solves the issue by only extending the list of channel registered
on the message when it is accepted, so that static channels are not unlinked
from the message.

Note that it is necessary to update `channel_ids` of the message,
because there could be "relay" channels. In other words, when the moderated
message is accepted, there could be more channels that contain this message.
This commit is contained in:
Alexandre Kühn
2018-06-29 12:57:05 +02:00
parent d54a3726ec
commit 5dcfb30fb3
2 changed files with 51 additions and 2 deletions
@@ -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--;
+50 -1
View File
@@ -372,4 +372,53 @@ QUnit.test("messaging menu widget: messaging menu with 1 message", function ( as
messagingMenu.destroy();
});
});
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: "<p>test</p>",
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();
});
});