From 694d501a359be079f70ebcdf7cb81c0b1a2b4ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 21 Apr 2023 07:50:50 +0000 Subject: [PATCH] [REF] mail, im_livechat: move /mail/chat_post to im_livechat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is only used there. In preparation of splitting discuss and mail modules. Part of task-3265211 closes odoo/odoo#119306 Signed-off-by: Sébastien Theys (seb) --- addons/im_livechat/controllers/main.py | 24 ++++++ .../public_models/livechat_button_view.js | 2 +- .../static/tests/discuss_patch_tests.js | 2 +- .../helpers/mock_server/controllers/main.js | 55 +++++++++++++ .../tests/messaging_service_patch_tests.js | 2 +- .../static/tests/sidebar_patch_tests.js | 2 +- addons/mail/controllers/__init__.py | 1 - addons/mail/controllers/bus.py | 37 --------- .../static/src/web/messaging_service_patch.js | 2 +- .../tests/chat_window/chat_window_tests.js | 81 +++++++++---------- .../static/tests/discuss/discuss_tests.js | 27 ++++--- .../helpers/mock_server/controllers/bus.js | 68 ---------------- .../static/tests/messaging/messaging_tests.js | 16 ++-- .../mail/static/tests/thread/thread_tests.js | 54 ++++++------- addons/website_livechat/tests/common.py | 2 +- 15 files changed, 173 insertions(+), 202 deletions(-) delete mode 100644 addons/mail/controllers/bus.py delete mode 100644 addons/mail/static/tests/helpers/mock_server/controllers/bus.js diff --git a/addons/im_livechat/controllers/main.py b/addons/im_livechat/controllers/main.py index 529e92945d9..1d396a6d0d8 100644 --- a/addons/im_livechat/controllers/main.py +++ b/addons/im_livechat/controllers/main.py @@ -212,6 +212,30 @@ class LivechatController(http.Controller): if discuss_channel: discuss_channel._close_livechat_session() + @http.route('/im_livechat/chat_post', type="json", auth="public", cors="*") + def im_livechat_chat_post(self, uuid, message_content): + channel = request.env["discuss.channel"].sudo().search([('uuid', '=', uuid)], limit=1) + if not channel: + return False + # find the author from the user session + if request.session.uid: + author = request.env['res.users'].sudo().browse(request.session.uid).partner_id + author_id = author.id + email_from = author.email_formatted + else: # If Public User, use catchall email from company + author_id = False + email_from = channel.anonymous_name or channel.create_uid.company_id.catchall_formatted + # post a message without adding followers to the channel. email_from=False avoid to get author from email data + body = tools.plaintext2html(message_content) + message = channel.with_context(mail_create_nosubscribe=True).message_post( + author_id=author_id, + email_from=email_from, + body=body, + message_type='comment', + subtype_xmlid='mail.mt_comment' + ) + return message.id if message else False + @http.route(['/im_livechat/chat_history'], type="json", auth="public", cors="*") def im_livechat_chat_history(self, uuid, last_id=False, limit=20): channel = request.env["discuss.channel"].sudo().search([('uuid', '=', uuid)], limit=1) diff --git a/addons/im_livechat/static/src/legacy/public_models/livechat_button_view.js b/addons/im_livechat/static/src/legacy/public_models/livechat_button_view.js index 8468b3ed536..76b8aff7f3c 100644 --- a/addons/im_livechat/static/src/legacy/public_models/livechat_button_view.js +++ b/addons/im_livechat/static/src/legacy/public_models/livechat_button_view.js @@ -308,7 +308,7 @@ Model({ typing: false, }); const messageId = await this.messaging.rpc({ - route: "/mail/chat_post", + route: "/im_livechat/chat_post", params: { uuid: this.messaging.publicLivechatGlobal.publicLivechat.uuid, message_content: message.content, diff --git a/addons/im_livechat/static/tests/discuss_patch_tests.js b/addons/im_livechat/static/tests/discuss_patch_tests.js index ba67e1e4843..441e154f1aa 100644 --- a/addons/im_livechat/static/tests/discuss_patch_tests.js +++ b/addons/im_livechat/static/tests/discuss_patch_tests.js @@ -89,7 +89,7 @@ QUnit.test("add livechat in the sidebar on visitor sending first message", async // simulate livechat visitor sending a message const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]); await afterNextRender(async () => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/im_livechat/chat_post", { context: { mockedUserId: false }, uuid: channel.uuid, message_content: "new message", diff --git a/addons/im_livechat/static/tests/helpers/mock_server/controllers/main.js b/addons/im_livechat/static/tests/helpers/mock_server/controllers/main.js index 8272b75876b..6028493843c 100644 --- a/addons/im_livechat/static/tests/helpers/mock_server/controllers/main.js +++ b/addons/im_livechat/static/tests/helpers/mock_server/controllers/main.js @@ -26,6 +26,12 @@ patch(MockServer.prototype, "im_livechat/controllers/main", { const context = args.context; return this._mockRouteImLivechatNotifyTyping(uuid, is_typing, context); } + if (route === "/im_livechat/chat_post") { + const uuid = args.uuid; + const message_content = args.message_content; + const context = args.context; + return this._mockRouteImLivechatChatPost(uuid, message_content, context); + } return this._super(...arguments); }, /** @@ -85,4 +91,53 @@ patch(MockServer.prototype, "im_livechat/controllers/main", { ]); this._mockDiscussChannelMember_NotifyTyping([memberOfCurrentUser.id], is_typing); }, + /** + * Simulates the `/im_livechat/chat_post` route. + * + * @private + * @param {string} uuid + * @param {string} message_content + * @param {Object} [context={}] + * @returns {Object} one key for list of followers and one for subtypes + */ + async _mockRouteImLivechatChatPost(uuid, message_content, context = {}) { + const channel = this.getRecords("discuss.channel", [["uuid", "=", uuid]])[0]; + if (!channel) { + return false; + } + + let user_id; + // find the author from the user session + if ("mockedUserId" in context) { + // can be falsy to simulate not being logged in + user_id = context.mockedUserId; + } else { + user_id = this.currentUserId; + } + let author_id; + let email_from; + if (user_id) { + const author = this.getRecords("res.users", [["id", "=", user_id]])[0]; + author_id = author.partner_id; + email_from = `${author.display_name} <${author.email}>`; + } else { + author_id = false; + // simpler fallback than catchall_formatted + email_from = channel.anonymous_name || "catchall@example.com"; + } + // supposedly should convert plain text to html + const body = message_content; + // ideally should be posted with mail_create_nosubscribe=True + return this._mockDiscussChannelMessagePost( + channel.id, + { + author_id, + email_from, + body, + message_type: "comment", + subtype_xmlid: "mail.mt_comment", + }, + context + ); + }, }); diff --git a/addons/im_livechat/static/tests/messaging_service_patch_tests.js b/addons/im_livechat/static/tests/messaging_service_patch_tests.js index d41271a2442..632d6a851f5 100644 --- a/addons/im_livechat/static/tests/messaging_service_patch_tests.js +++ b/addons/im_livechat/static/tests/messaging_service_patch_tests.js @@ -29,7 +29,7 @@ QUnit.test("Notify message received out of focus", async (assert) => { }), }, }); - await env.services.rpc("/mail/chat_post", { + await env.services.rpc("/im_livechat/chat_post", { context: { mockedUserId: senderId }, message_content: "Hello", uuid: channel.uuid, diff --git a/addons/im_livechat/static/tests/sidebar_patch_tests.js b/addons/im_livechat/static/tests/sidebar_patch_tests.js index 1e767d853e2..2fed3d78ad1 100644 --- a/addons/im_livechat/static/tests/sidebar_patch_tests.js +++ b/addons/im_livechat/static/tests/sidebar_patch_tests.js @@ -466,7 +466,7 @@ QUnit.test("Message unread counter", async (assert) => { const { env, openDiscuss } = await start(); await openDiscuss(); await afterNextRender(async () => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/im_livechat/chat_post", { context: { mockedUserId: userId }, message_content: "hu", uuid: pyEnv["discuss.channel"].searchRead([["id", "=", channelId]])[0].uuid, diff --git a/addons/mail/controllers/__init__.py b/addons/mail/controllers/__init__.py index 58fc160ae64..10fb0480208 100644 --- a/addons/mail/controllers/__init__.py +++ b/addons/mail/controllers/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -* # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import bus from . import discuss from . import mail diff --git a/addons/mail/controllers/bus.py b/addons/mail/controllers/bus.py deleted file mode 100644 index 87b73c4a0af..00000000000 --- a/addons/mail/controllers/bus.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import SUPERUSER_ID, tools -from odoo.http import request, route -from odoo.addons.bus.controllers.main import BusController - - -class MailChatController(BusController): - - # -------------------------- - # Anonymous routes (Common Methods) - # -------------------------- - @route('/mail/chat_post', type="json", auth="public", cors="*") - def mail_chat_post(self, uuid, message_content, **kwargs): - channel = request.env["discuss.channel"].sudo().search([('uuid', '=', uuid)], limit=1) - if not channel: - return False - - # find the author from the user session - if request.session.uid: - author = request.env['res.users'].sudo().browse(request.session.uid).partner_id - author_id = author.id - email_from = author.email_formatted - else: # If Public User, use catchall email from company - author_id = False - email_from = channel.anonymous_name or channel.create_uid.company_id.catchall_formatted - # post a message without adding followers to the channel. email_from=False avoid to get author from email data - body = tools.plaintext2html(message_content) - message = channel.with_context(mail_create_nosubscribe=True).message_post( - author_id=author_id, - email_from=email_from, - body=body, - message_type='comment', - subtype_xmlid='mail.mt_comment' - ) - return message.id if message else False diff --git a/addons/mail/static/src/web/messaging_service_patch.js b/addons/mail/static/src/web/messaging_service_patch.js index 0c8ea928595..6c94371c93c 100644 --- a/addons/mail/static/src/web/messaging_service_patch.js +++ b/addons/mail/static/src/web/messaging_service_patch.js @@ -27,7 +27,7 @@ patch(Messaging.prototype, "mail/web", { async _handleNotificationNewMessage(notif) { await this._super(notif); const channel = this.store.threads[createLocalId("discuss.channel", notif.payload.id)]; - if (channel.correspondent !== this.store.odoobot) { + if (!this.store.isSmall && channel.correspondent !== this.store.odoobot) { this.chatWindowService.insert({ thread: channel }); } }, diff --git a/addons/mail/static/tests/chat_window/chat_window_tests.js b/addons/mail/static/tests/chat_window/chat_window_tests.js index 68365806978..1a9d8f9d8f0 100644 --- a/addons/mail/static/tests/chat_window/chat_window_tests.js +++ b/addons/mail/static/tests/chat_window/chat_window_tests.js @@ -29,25 +29,22 @@ QUnit.test( const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "Demo" }); const userId = pyEnv["res.users"].create({ partner_id: partnerId }); - pyEnv["discuss.channel"].records = [ - { - channel_member_ids: [ - [0, 0, { partner_id: pyEnv.currentPartnerId }], - [0, 0, { partner_id: partnerId }], - ], - channel_type: "chat", - id: partnerId, - uuid: "channel-10-uuid", - }, - ]; + const channelId = pyEnv["discuss.channel"].create({ + channel_member_ids: [ + [0, 0, { partner_id: pyEnv.currentPartnerId }], + [0, 0, { partner_id: partnerId }], + ], + channel_type: "chat", + }); patchUiSize({ size: SIZES.SM }); const { env } = await start(); // simulate receiving a message - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hu", - uuid: "channel-10-uuid", + post_data: { body: "hu", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }); await nextAnimationFrame(); assert.containsNone($, ".o-mail-ChatWindow"); @@ -568,7 +565,6 @@ QUnit.test( [0, 0, { partner_id: partnerId }], ], channel_type: "chat", - uuid: "channel-10-uuid", }); const messageId = pyEnv["mail.message"].create({ body: "not empty", @@ -583,10 +579,11 @@ QUnit.test( const { env } = await start(); // simulate receiving a message await afterNextRender(async () => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hu", - uuid: "channel-10-uuid", + post_data: { body: "hu", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsOnce($, ".o-mail-ChatWindow"); @@ -604,21 +601,21 @@ QUnit.test( name: "Foreigner user", partner_id: partnerId, }); - pyEnv["discuss.channel"].create({ + const channelId = pyEnv["discuss.channel"].create({ channel_member_ids: [ [0, 0, { partner_id: pyEnv.currentPartnerId }], [0, 0, { partner_id: partnerId }], ], channel_type: "chat", - uuid: "channel-10-uuid", }); const { env } = await start(); // simulate receiving a message await afterNextRender(async () => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hu", - uuid: "channel-10-uuid", + post_data: { body: "hu", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsOnce($, "hr + span:contains(New messages)"); @@ -629,23 +626,23 @@ QUnit.test("chat window should open when receiving a new DM", async (assert) => const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({}); const userId = pyEnv["res.users"].create({ partner_id: partnerId }); - pyEnv["discuss.channel"].create({ + const channelId = pyEnv["discuss.channel"].create({ channel_member_ids: [ [0, 0, { is_pinned: false, partner_id: pyEnv.currentPartnerId }], [0, 0, { partner_id: partnerId }], ], channel_type: "chat", - uuid: "channel-uuid", }); const { env } = await start(); // simulate receiving the first message on chat await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId, }, - message_content: "new message", - uuid: "channel-uuid", + post_data: { body: "new message", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsOnce($, ".o-mail-ChatWindow"); @@ -654,21 +651,21 @@ QUnit.test("chat window should open when receiving a new DM", async (assert) => QUnit.test("chat window should not open when receiving a new DM from odoobot", async (assert) => { const pyEnv = await startServer(); const userId = pyEnv["res.users"].create({ partner_id: pyEnv.odoobotId }); - pyEnv["discuss.channel"].create({ + const channelId = pyEnv["discuss.channel"].create({ channel_member_ids: [ [0, 0, { is_pinned: false, partner_id: pyEnv.currentPartnerId }], [0, 0, { partner_id: pyEnv.odoobotId }], ], channel_type: "chat", - uuid: "channel-uuid", }); const { env } = await start(); // simulate receiving new message from odoobot await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "new message", - uuid: "channel-uuid", + post_data: { body: "new message", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsNone($, ".o-mail-ChatWindow"); @@ -712,7 +709,7 @@ QUnit.test("chat window should remain folded when new message is received", asyn name: "Foreigner user", partner_id: partnerId, }); - pyEnv["discuss.channel"].create({ + const channelId = pyEnv["discuss.channel"].create({ channel_member_ids: [ [ 0, @@ -726,15 +723,15 @@ QUnit.test("chat window should remain folded when new message is received", asyn [0, 0, { partner_id: partnerId }], ], channel_type: "chat", - uuid: "channel-uuid", }); const { env } = await start(); assert.hasClass($(".o-mail-ChatWindow"), "o-folded"); - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "New Message", - uuid: "channel-uuid", + post_data: { body: "New Message", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }); await nextTick(); assert.hasClass($(".o-mail-ChatWindow"), "o-folded"); @@ -839,7 +836,6 @@ QUnit.test( [0, 0, { partner_id: partnerId }], ], channel_type: "chat", - uuid: "channel-10-uuid", }); const messageId = pyEnv["mail.message"].create([ { @@ -857,10 +853,11 @@ QUnit.test( $(".o-mail-Composer-input")[0].blur(); // simulate receiving a message await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hu", - uuid: "channel-10-uuid", + post_data: { body: "hu", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsOnce($, "hr + span:contains(New messages)"); diff --git a/addons/mail/static/tests/discuss/discuss_tests.js b/addons/mail/static/tests/discuss/discuss_tests.js index 8973b03eaeb..8b282303353 100644 --- a/addons/mail/static/tests/discuss/discuss_tests.js +++ b/addons/mail/static/tests/discuss/discuss_tests.js @@ -1166,13 +1166,12 @@ QUnit.test("should auto-pin chat when receiving a new DM", async (assert) => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "Demo" }); const userId = pyEnv["res.users"].create({ partner_id: partnerId }); - pyEnv["discuss.channel"].create({ + const channelId = pyEnv["discuss.channel"].create({ channel_member_ids: [ [0, 0, { is_pinned: false, partner_id: pyEnv.currentPartnerId }], [0, 0, { partner_id: partnerId }], ], channel_type: "chat", - uuid: "channel11uuid", }); const { env, openDiscuss } = await start(); await openDiscuss(); @@ -1180,10 +1179,11 @@ QUnit.test("should auto-pin chat when receiving a new DM", async (assert) => { // simulate receiving the first message on channel 11 await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "new message", - uuid: "channel11uuid", + post_data: { body: "new message", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsOnce($, ".o-mail-DiscussCategoryItem:contains(Demo)"); @@ -1565,7 +1565,7 @@ QUnit.test("new messages separator [REQUIRE FOCUS]", async (assert) => { name: "Foreigner user", partner_id: partnerId, }); - const channelId = pyEnv["discuss.channel"].create({ name: "test", uuid: "randomuuid" }); + const channelId = pyEnv["discuss.channel"].create({ name: "test" }); let lastMessageId; for (let i = 1; i <= 25; i++) { lastMessageId = pyEnv["mail.message"].create({ @@ -1589,10 +1589,11 @@ QUnit.test("new messages separator [REQUIRE FOCUS]", async (assert) => { $(".o-mail-Composer-input")[0].blur(); // simulate receiving a message await afterNextRender(async () => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hu", - uuid: "randomuuid", + post_data: { body: "hu", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsN($, ".o-mail-Message", 26); @@ -1894,13 +1895,13 @@ QUnit.test("Message shows up even if channel data is incomplete", async (assert) is_typing: true, channel_id: channelId, }); - const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]); await afterNextRender( async () => - await env.services.rpc("/mail/chat_post", { + await env.services.rpc("/mail/message/post", { context: { mockedUserId: correspondentUserId }, - message_content: "hello world", - uuid: channel.uuid, + post_data: { body: "hello world", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); await click(".o-mail-DiscussCategory-chat + .o-mail-DiscussCategoryItem:contains(Albert)"); diff --git a/addons/mail/static/tests/helpers/mock_server/controllers/bus.js b/addons/mail/static/tests/helpers/mock_server/controllers/bus.js deleted file mode 100644 index b791fe5f8ce..00000000000 --- a/addons/mail/static/tests/helpers/mock_server/controllers/bus.js +++ /dev/null @@ -1,68 +0,0 @@ -/** @odoo-module **/ - -import { patch } from "@web/core/utils/patch"; -import { MockServer } from "@web/../tests/helpers/mock_server"; - -patch(MockServer.prototype, "mail/controllers/bus", { - /** - * @override - */ - async _performRPC(route, args) { - if (route === "/mail/chat_post") { - const uuid = args.uuid; - const message_content = args.message_content; - const context = args.context; - return this._mockRouteMailChatPost(uuid, message_content, context); - } - return this._super(route, args); - }, - /** - * Simulates the `/mail/chat_post` route. - * - * @private - * @param {string} uuid - * @param {string} message_content - * @param {Object} [context={}] - * @returns {Object} one key for list of followers and one for subtypes - */ - async _mockRouteMailChatPost(uuid, message_content, context = {}) { - const channel = this.getRecords("discuss.channel", [["uuid", "=", uuid]])[0]; - if (!channel) { - return false; - } - - let user_id; - // find the author from the user session - if ("mockedUserId" in context) { - // can be falsy to simulate not being logged in - user_id = context.mockedUserId; - } else { - user_id = this.currentUserId; - } - let author_id; - let email_from; - if (user_id) { - const author = this.getRecords("res.users", [["id", "=", user_id]])[0]; - author_id = author.partner_id; - email_from = `${author.display_name} <${author.email}>`; - } else { - author_id = false; - // simpler fallback than catchall_formatted - email_from = channel.anonymous_name || "catchall@example.com"; - } - // supposedly should convert plain text to html - const body = message_content; - // ideally should be posted with mail_create_nosubscribe=True - return this._mockDiscussChannelMessagePost( - channel.id, - { - author_id, - email_from, - body, - message_type: "comment", - subtype_xmlid: "mail.mt_comment", - }, - context - ); - }, -}); diff --git a/addons/mail/static/tests/messaging/messaging_tests.js b/addons/mail/static/tests/messaging/messaging_tests.js index ee203dc03d6..b35c85d34f5 100644 --- a/addons/mail/static/tests/messaging/messaging_tests.js +++ b/addons/mail/static/tests/messaging/messaging_tests.js @@ -17,12 +17,12 @@ QUnit.test( ], channel_type: "chat", }); - const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]); await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "new message", - uuid: channel.uuid, + post_data: { body: "new message", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsOnce($, ".o-mail-ChatWindow-header:contains(Dumbledore)"); @@ -43,11 +43,11 @@ QUnit.test( ], channel_type: "chat", }); - const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]); - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "new message", - uuid: channel.uuid, + post_data: { body: "new message", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }); // leaving discuss. await openFormView("res.partner", partnerId); diff --git a/addons/mail/static/tests/thread/thread_tests.js b/addons/mail/static/tests/thread/thread_tests.js index 913cb165fb1..fd98f8ae810 100644 --- a/addons/mail/static/tests/thread/thread_tests.js +++ b/addons/mail/static/tests/thread/thread_tests.js @@ -239,7 +239,6 @@ QUnit.test( const userId = pyEnv["res.users"].create({ partner_id: partnerId }); const channelId = pyEnv["discuss.channel"].create({ name: "test", - uuid: "uuid-uuid", channel_member_ids: [ [0, 0, { partner_id: pyEnv.currentPartnerId }], [0, 0, { partner_id: partnerId }], @@ -260,10 +259,11 @@ QUnit.test( }); await click(".o_menu_systray i[aria-label='Messages']"); await afterNextRender(async () => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "new message", - uuid: "uuid-uuid", + post_data: { body: "new message", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.verifySteps(["rpc:channel_fetch"]); @@ -280,10 +280,7 @@ QUnit.test( const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({}); const userId = pyEnv["res.users"].create({ partner_id: partnerId }); - const channelId = pyEnv["discuss.channel"].create({ - name: "test", - uuid: "uuid-uuid", - }); + const channelId = pyEnv["discuss.channel"].create({ name: "test" }); const deferred = makeDeferred(); const { env, openDiscuss } = await start({ async mockRPC(route, args) { @@ -301,10 +298,11 @@ QUnit.test( await openDiscuss(channelId); $(".o-mail-Composer-input")[0].focus(); // simulate receiving a message - await env.services.rpc("/mail/chat_post", { + await env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "

Some new message

", - uuid: "uuid-uuid", + post_data: { body: "

Some new message

", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }); await afterNextRender(() => deferred.resolve()); assert.verifySteps(["rpc:set_last_seen_message"]); @@ -317,7 +315,7 @@ QUnit.test( const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "Foreigner partner" }); const userId = pyEnv["res.users"].create({ name: "Foreigner user", partner_id: partnerId }); - const channelId = pyEnv["discuss.channel"].create({ uuid: "channel-uuid" }); + const channelId = pyEnv["discuss.channel"].create({}); for (let i = 0; i <= 10; i++) { pyEnv["mail.message"].create({ body: "not empty", @@ -332,10 +330,11 @@ QUnit.test( // simulate receiving a message await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hello", - uuid: "channel-uuid", + post_data: { body: "hello", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.ok(isScrolledToBottom($(".o-mail-Thread")[0])); @@ -348,7 +347,7 @@ QUnit.test( const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "Foreigner partner" }); const userId = pyEnv["res.users"].create({ name: "Foreigner user", partner_id: partnerId }); - const channelId = pyEnv["discuss.channel"].create({ uuid: "channel-uuid" }); + const channelId = pyEnv["discuss.channel"].create({}); for (let i = 0; i <= 10; i++) { pyEnv["mail.message"].create({ body: "not empty", @@ -367,10 +366,11 @@ QUnit.test( // simulate receiving a message await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hello", - uuid: "channel-uuid", + post_data: { body: "hello", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.strictEqual($(".o-mail-Thread")[0].scrollTop, 0); @@ -474,7 +474,6 @@ QUnit.test("new messages separator on receiving new message [REQUIRE FOCUS]", as ], channel_type: "channel", name: "General", - uuid: "randomuuid", }); const messageId = pyEnv["mail.message"].create({ body: "blah", @@ -494,10 +493,11 @@ QUnit.test("new messages separator on receiving new message [REQUIRE FOCUS]", as $(".o-mail-Composer-input")[0].blur(); // simulate receiving a message await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "hu", - uuid: "randomuuid", + post_data: { body: "hu", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsN($, ".o-mail-Message", 2); @@ -731,7 +731,6 @@ QUnit.test( const channelId = pyEnv["discuss.channel"].create({ channel_type: "channel", name: "General", - uuid: "channel20uuid", }); pyEnv["mail.message"].create([ { @@ -749,10 +748,11 @@ QUnit.test( $(".o-mail-Composer-input")[0].blur(); // simulate receiving a message await afterNextRender(() => - env.services.rpc("/mail/chat_post", { + env.services.rpc("/mail/message/post", { context: { mockedUserId: userId }, - message_content: "test", - uuid: "channel20uuid", + post_data: { body: "test", message_type: "comment" }, + thread_id: channelId, + thread_model: "discuss.channel", }) ); assert.containsN($, ".o-mail-Message", 3); diff --git a/addons/website_livechat/tests/common.py b/addons/website_livechat/tests/common.py index 8df1af0f383..fe11c2b1045 100644 --- a/addons/website_livechat/tests/common.py +++ b/addons/website_livechat/tests/common.py @@ -73,7 +73,7 @@ class TestLivechatCommon(tests.TransactionCase): self.patch(type(self.env['website.visitor']), '_get_visitor_from_request', get_visitor_from_request) def _send_message(self, channel, email_from, body, author_id=False): - # As bus is unavailable in test mode, we cannot call /mail/chat_post route to post a message. + # As bus is unavailable in test mode, we cannot call /im_livechat/chat_post route to post a message. # Instead, we post directly the message on the given channel. channel.with_context(mail_create_nosubscribe=True) \ .message_post(author_id=author_id, email_from=email_from, body=body,