diff options
| author | Alexandre Kühn <aku@odoo.com> | 2020-09-10 16:34:50 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2020-09-24 17:59:12 +0000 |
| commit | b39f39b598d3a930034f9981712cf5ec41ad301c (patch) | |
| tree | 26265a176e9731898ab4b9a13c5fdd048c775fa4 /addons/website_livechat/static/src/models/messaging_notification_handler | |
| parent | 5fe3ad548e410fbe2eddd7f67aa4b89b81746f1a (diff) | |
[FIX] im_livechat, mail, website_livechat: open chat website visitor
Also fix an issue with livechats not being considered in 'chat'
filter of messaging menu.
Task-Id 2282426
closes odoo/odoo#58466
X-original-commit: 631e52536964763bbfe857305f023e5e67084e95
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/website_livechat/static/src/models/messaging_notification_handler')
2 files changed, 130 insertions, 0 deletions
diff --git a/addons/website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js new file mode 100644 index 00000000000..d43957ba374 --- /dev/null +++ b/addons/website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js @@ -0,0 +1,32 @@ +odoo.define('website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js', function (require) { +'use strict'; + +const { registerInstancePatchModel } = require('mail/static/src/model/model_core.js'); + +registerInstancePatchModel('mail.messaging_notification_handler', 'website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler.js', { + + //---------------------------------------------------------------------- + // Private + //---------------------------------------------------------------------- + + /** + * @override + */ + _handleNotificationPartner(data) { + const { info } = data; + if (info === 'send_chat_request') { + this._handleNotificationPartnerChannel(data); + const channel = this.env.models['mail.thread'].findFromIdentifyingData({ + id: data.id, + model: 'mail.channel', + }); + this.env.messaging.chatWindowManager.openThread(channel, { + makeActive: true, + }); + return; + } + return this._super(data); + }, +}); + +}); diff --git a/addons/website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler_tests.js b/addons/website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler_tests.js new file mode 100644 index 00000000000..4130af641b3 --- /dev/null +++ b/addons/website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler_tests.js @@ -0,0 +1,98 @@ +odoo.define('website_livechat/static/src/models/messaging_notification_handler/messaging_notification_handler_tests.js', function (require) { +'use strict'; + +const { + afterEach, + afterNextRender, + beforeEach, + start, +} = require('mail/static/src/utils/test_utils.js'); + +const FormView = require('web.FormView'); +const { + mock: { + intercept, + }, +} = require('web.test_utils'); + +QUnit.module('website_livechat', {}, function () { +QUnit.module('models', {}, function () { +QUnit.module('messaging_notification_handler', {}, function () { +QUnit.module('messaging_notification_handler_tests.js', { + beforeEach() { + beforeEach(this); + + this.start = async params => { + const { env, widget } = await start(Object.assign({}, { + data: this.data, + }, params)); + this.env = env; + this.widget = widget; + }; + }, + afterEach() { + afterEach(this); + }, +}); + +QUnit.test('should open chat window on send chat request to website visitor', async function (assert) { + assert.expect(3); + + this.data['website.visitor'].records.push({ + id: 11, + name: "Visitor #11", + }); + await this.start({ + data: this.data, + hasChatWindow: true, + hasView: true, + // View params + View: FormView, + model: 'website.visitor', + arch: ` + <form> + <header> + <button name="action_send_chat_request" string="Send chat request" class="btn btn-primary" type="button"/> + </header> + <field name="name"/> + </form> + `, + res_id: 11, + }); + intercept(this.widget, 'execute_action', payload => { + this.env.services.rpc({ + route: '/web/dataset/call_button', + params: { + args: [payload.data.env.resIDs], + kwargs: { context: payload.data.env.context }, + method: payload.data.action_data.name, + model: payload.data.env.model, + } + }); + }); + + await afterNextRender(() => + document.querySelector('button[name="action_send_chat_request"]').click() + ); + assert.containsOnce( + document.body, + '.o_ChatWindow', + "should have a chat window open after sending chat request to website visitor" + ); + assert.hasClass( + document.querySelector('.o_ChatWindow'), + 'o-focused', + "chat window of livechat should be focused on open" + ); + assert.strictEqual( + document.querySelector('.o_ChatWindowHeader_name').textContent, + "Visitor #11", + "chat window of livechat should have name of visitor in the name" + ); +}); + +}); +}); +}); + +}); |
