Skip to content
Snippets Groups Projects
Commit f61b4669 authored by Alexandre Kühn's avatar Alexandre Kühn
Browse files

[FIX] mail: no traceback on click channel mention from chat window


Before this commit, when clicking on a channel mention from a chat
window, it crashed with the following error:

`TypeError: channel.detach is not a function`

This happens due to `MailService.joinChannel()` returning a promise
that is resolved with channel ID, instead of a channel object.
`channel.detach()` becomes `<Number>.detach()`, which is treated
like `undefined()`, hence crash.

closes odoo/odoo#44329

X-original-commit: 710fda06
Signed-off-by: default avatarAlexandre Kühn (aku) <aku@odoo.com>
parent cd70571d
No related branches found
No related tags found
No related merge requests found
......@@ -351,10 +351,12 @@ var ThreadWindow = AbstractThreadWindow.extend({
* @param {integer} channelID
*/
_onRedirectToChannel: function (channelID) {
var self = this;
var thread = this.call('mail_service', 'getThread', channelID);
if (!thread) {
this.call('mail_service', 'joinChannel', channelID)
.then(function (channel) {
.then(function (channelID) {
var channel = self.call('mail_service', 'getThread', channelID);
channel.detach();
});
} else {
......
......@@ -903,6 +903,92 @@ QUnit.test('non-deletable message attachments', async function (assert) {
parent.destroy();
});
QUnit.test('join channel from click channel mention', async function (assert) {
assert.expect(10);
this.data['mail.channel'].records = [{
id: 2,
name: "R&D Tasks",
channel_type: "channel",
}];
this.data['mail.message'].records.push({
author_id: [5, "Someone else"],
body: `<p><a href="#" class="o_mail_redirect" data-oe-id="2" data-oe-model="mail.channel">#R&D Tasks</a></p>`,
id: 10,
res_id: 1,
channel_ids: [1],
});
const parent = this.createParent({
data: this.data,
services: this.services,
session: { partner_id: 3 },
async mockRPC(route, args) {
if (args.method === 'channel_join_and_get_info') {
const channelID = args.args[0][0];
assert.step(`channel_join_and_get_info:${channelID}`);
return this.data['mail.channel'].records.find(channel => channel.id === channelID);
}
return this._super(...arguments);
},
});
await testUtils.nextTick();
assert.containsNone(
$,
'.o_thread_window',
"no thread window should be open initially"
);
// get channel instance to link to thread window
const channel = parent.call('mail_service', 'getChannel', 1);
channel.detach();
await testUtils.nextTick();
assert.containsOnce(
$,
'.o_thread_window',
"should have one thread open in chat window"
);
assert.strictEqual(
$('.o_thread_window .o_thread_window_title').text().trim(),
"#general",
"should have thread '#general' as open in chat window"
);
assert.containsOnce(
$,
'.o_thread_window .o_thread_message',
"should contain a single message in chat window"
);
assert.containsOnce(
$,
'.o_thread_window .o_thread_message a.o_mail_redirect',
"message should have a mention"
);
assert.containsOnce(
$,
'.o_thread_window .o_thread_message a.o_mail_redirect[data-oe-id="2"][data-oe-model="mail.channel"]',
"message should have a channel mention to R&D Task"
);
await testUtils.dom.click($('.o_thread_window .o_thread_message a.o_mail_redirect[data-oe-id="2"][data-oe-model="mail.channel"]'));
assert.verifySteps(
['channel_join_and_get_info:2'],
"should have joined channel #R&D Task"
);
assert.containsN(
$,
'.o_thread_window',
2,
"should now have 2 threads open in chat windows after cliking on channel mention"
);
assert.strictEqual(
$('.o_thread_window .o_thread_window_title').text().replace(/\s/g, ""),
"#general#R&DTasks",
"should have threads '#general' and '#R&D Tasks' as open in chat windows"
);
parent.destroy();
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment