[FIX] mail: allow to open record thread in chat window

task-2171885

closes odoo/odoo#58324

X-original-commit: af6e68c2c5bd819402af0126c87f375e096c8d0d
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2020-09-23 11:01:18 +00:00
parent 071dd1b451
commit ff209a8b36
4 changed files with 143 additions and 35 deletions
@@ -171,7 +171,7 @@ QUnit.test('mark as read', async function (assert) {
QUnit.test('grouped notifications by document', async function (assert) {
// If some failures linked to a document refers to a same document, a single
// notification should group all those failures.
assert.expect(9);
assert.expect(5);
this.data['mail.message'].records.push(
// first message that is expected to have a failure
@@ -205,31 +205,7 @@ QUnit.test('grouped notifications by document', async function (assert) {
notification_type: 'email', // expected failure type for email message
}
);
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
assert.strictEqual(
payload.action.type,
'ir.actions.act_window',
"action should have the type act_window"
);
assert.strictEqual(
payload.action.res_model,
'res.partner',
"action should have the group model as res_model"
);
assert.strictEqual(
JSON.stringify(payload.action.views),
JSON.stringify([[false, 'form']]),
"action should have form view"
);
assert.strictEqual(
payload.action.res_id,
31,
"action should have the group res_id as res_id"
);
});
await this.start({ env: { bus } });
await this.start({ hasChatWindow: true });
await this.createNotificationListComponent();
assert.containsOnce(
@@ -247,11 +223,19 @@ QUnit.test('grouped notifications by document', async function (assert) {
"(2)",
"should have 2 notifications in the group"
);
assert.containsNone(
document.body,
'.o_ChatWindow',
"should have no chat window initially"
);
document.querySelector('.o_NotificationGroup').click();
assert.verifySteps(
['do_action'],
"should do an action to display the related record"
await afterNextRender(() =>
document.querySelector('.o_NotificationGroup').click()
);
assert.containsOnce(
document.body,
'.o_ChatWindow',
"should have opened the thread in a chat window after clicking on it"
);
});
@@ -105,6 +105,7 @@ class ThreadNeedactionPreview extends Component {
// handled in `_onClickMarkAsRead`
return;
}
this.thread.markNeedactionMessagesAsRead();
this.thread.open();
if (!this.env.messaging.device.isMobile) {
this.env.messaging.messagingMenu.close();
@@ -13,6 +13,8 @@ const {
start,
} = require('mail/static/src/utils/test_utils.js');
const Bus = require('web.Bus');
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_needaction_preview', {}, function () {
@@ -84,6 +86,121 @@ QUnit.test('mark as read', async function (assert) {
);
});
QUnit.test('click on preview should mark as read and open the thread', async function (assert) {
assert.expect(5);
await this.start({
hasChatWindow: true,
async mockRPC(route, args) {
if (route.includes('set_message_done')) {
assert.step('set_message_done');
}
return this._super(...arguments);
},
});
const thread = this.env.models['mail.thread'].create({
id: 11,
model: 'mail.channel',
});
this.env.models['mail.message'].create({
id: 21,
isNeedaction: true,
originThread: [['link', thread]],
});
await this.createThreadNeedactionPreviewComponent({
threadLocalId: thread.localId,
});
assert.containsOnce(
document.body,
'.o_ThreadNeedactionPreview',
"should have a preview initially"
);
assert.containsNone(
document.body,
'.o_ChatWindow',
"should have no chat window initially"
);
await afterNextRender(() =>
document.querySelector('.o_ThreadNeedactionPreview').click()
);
assert.verifySteps(
['set_message_done'],
"should have marked the message as read on clicking on the preview"
);
assert.containsOnce(
document.body,
'.o_ChatWindow',
"should have opened the thread on clicking on the preview"
);
});
QUnit.test('click on expand from chat window should close the chat window and open the form view', async function (assert) {
assert.expect(8);
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
assert.strictEqual(
payload.action.res_id,
11,
"should redirect to the id of the thread"
);
assert.strictEqual(
payload.action.res_model,
'res.partner',
"should redirect to the model of the thread"
);
});
await this.start({
env: { bus },
hasChatWindow: true,
});
const thread = this.env.models['mail.thread'].create({
id: 11,
model: 'res.partner',
});
this.env.models['mail.message'].create({
id: 21,
isNeedaction: true,
originThread: [['link', thread]],
});
await this.createThreadNeedactionPreviewComponent({
threadLocalId: thread.localId,
});
assert.containsOnce(
document.body,
'.o_ThreadNeedactionPreview',
"should have a preview initially"
);
await afterNextRender(() =>
document.querySelector('.o_ThreadNeedactionPreview').click()
);
assert.containsOnce(
document.body,
'.o_ChatWindow',
"should have opened the thread on clicking on the preview"
);
assert.containsOnce(
document.body,
'.o_ChatWindowHeader_commandExpand',
"should have an expand button"
);
await afterNextRender(() =>
document.querySelector('.o_ChatWindowHeader_commandExpand').click()
);
assert.containsNone(
document.body,
'.o_ChatWindow',
"should have closed the chat window on clicking expand"
);
assert.verifySteps(
['do_action'],
"should have done an action to open the form view"
);
});
});
});
});
+11 -5
View File
@@ -631,16 +631,22 @@ function factory(dependencies) {
* @param {boolean} [param0.expanded=false]
*/
async open({ expanded = false } = {}) {
const discuss = this.env.messaging.discuss;
// check if thread must be opened in form view
if (!['mail.box', 'mail.channel'].includes(this.model)) {
return this.env.messaging.openDocument({
id: this.id,
model: this.model,
});
if (expanded || discuss.isOpen) {
// Close chat window because having the same thread opened
// both in chat window and as main document does not look
// good.
this.env.messaging.chatWindowManager.closeThread(this);
return this.env.messaging.openDocument({
id: this.id,
model: this.model,
});
}
}
// check if thread must be opened in discuss
const device = this.env.messaging.device;
const discuss = this.env.messaging.discuss;
if (
(!device.isMobile && (discuss.isOpen || expanded)) ||
this.model === 'mail.box'