Skip to content
Permalink
Browse files

[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 #35724

Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
  • Loading branch information...
alexkuhn committed Aug 14, 2019
1 parent 52ad807 commit 9ea5aecee8065db286977f0289039c6a53a263e6
Showing with 67 additions and 1 deletion.
  1. +2 −1 addons/mail/static/src/js/services/mail_manager.js
  2. +65 −0 addons/mail/static/tests/discuss_tests.js
@@ -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;
},
@@ -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();
});

});
});

0 comments on commit 9ea5aec

Please sign in to comment.
You can’t perform that action at this time.