[FIX] mail: receive message then delayed needaction notifications

Before this commit, when a user received a needaction notification
on a message already stored locally, it crashed with this error:

`TypeError: Cannot read property 'getThreadIDs' of undefined`

This is caused by `addMessage` returning a Promise not resolved with
the message when the message is not new. The returned promise should
always be resolved with the message, in order to be consistent.

closes odoo/odoo#35724

Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
This commit is contained in:
Alexandre Kühn
2019-08-14 12:56:27 +00:00
parent 52ad807817
commit 9ea5aecee8
2 changed files with 67 additions and 1 deletions
@@ -85,7 +85,7 @@ var MailManager = AbstractService.extend({
addMessage: function (data, options) {
options = options || {};
var message = this.getMessage(data.id);
var prom = Promise.resolve();
var prom;
if (!message) {
prom = this._addNewMessage(data, options);
} else {
@@ -95,6 +95,7 @@ var MailManager = AbstractService.extend({
});
}
this._addMessageToThreads(message, options);
prom = Promise.resolve(message);
}
return prom;
},
+65
View File
@@ -60,6 +60,7 @@ QUnit.module('Discuss', {
type: 'integer',
},
},
records: [],
},
'res.partner': {
fields: {
@@ -1491,5 +1492,69 @@ QUnit.test('custom-named DM conversation', async function (assert) {
discuss.destroy();
});
QUnit.test('receive channel message notification then delayed needaction notification', async function (assert) {
assert.expect(3);
const message = {
author_id: [5, 'Demo User'],
body: '<p>test</p>',
channel_ids: [1],
id: 100,
model: 'mail.channel',
needaction: true,
needaction_partner_ids: [3],
res_id: 1,
};
this.data.initMessaging = {
channel_slots: {
channel_channel: [{
id: 1,
channel_type: 'channel',
name: "general",
}],
},
};
const discuss = await createDiscuss({
context: {},
params: {},
data: this.data,
services: this.services,
session: {
partner_id: 3
},
});
const $inbox = discuss.$('.o_mail_discuss_item[data-thread-id="mailbox_inbox"]');
assert.hasClass(
$inbox,
'o_active',
"'Inbox' should be the currently active thread");
assert.containsNone(
discuss,
'.o_thread_message',
"inbox should contain no messages initially");
// simulate new needaction message posted on channnel
this.data['mail.message'].records.push(message);
// simulate receiving channel notification
discuss.call('bus_service', 'trigger', 'notification', [
[['myDB', 'mail.channel', 1], message]
]);
// short delay after receiving needaction notification
await testUtils.nextTick();
// simulate receiving needaction message notification after a short delay
discuss.call('bus_service', 'trigger', 'notification', [
[['myDB', 'ir.needaction', 3], message]
]);
await testUtils.nextTick();
assert.containsOnce(
discuss,
'.o_thread_message',
"inbox should contain one message");
discuss.destroy();
});
});
});