From f728b2d97abcee53aff2efd85d8b60ea4639c7dd Mon Sep 17 00:00:00 2001 From: Priyanka Kakadiya Date: Fri, 5 Feb 2021 05:03:39 +0000 Subject: [PATCH] [FIX] mail: fix new message chatwindow issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current behavior before PR: When looking for a user through the new message chat window, if there is already a chat open for this user, the new message window is still open on selecting the user. Desired behavior after PR is merged: when opening a chat from a new message, if the chat with this user is already open then it will close the new message chat window on selecting the user. LINKS: PR https://github.com/odoo/odoo/pull/65851 Task-2449118 closes odoo/odoo#66085 X-original-commit: 016dedf172f750a0fcb1138a798faf2a224d513e Signed-off-by: Sébastien Theys (seb) --- .../chat_window_manager_tests.js | 55 +++++++++++++++++++ .../chat_window_manager.js | 5 +- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js index ef26aa4d785..b581711a4ce 100644 --- a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js +++ b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js @@ -378,6 +378,61 @@ QUnit.test('open chat from "new message" chat window should open chat in place o ); }); +QUnit.test('new message chat window should close on selecting the user if chat with the user is already open', async function (assert) { + assert.expect(2); + + this.data['res.partner'].records.push({ id: 131, name: "Partner 131"}); + this.data['res.users'].records.push({ id: 12, partner_id: 131 }); + this.data['mail.channel'].records.push({ + channel_type: "chat", + id: 20, + is_minimized: true, + members: [this.data.currentPartnerId, 131], + name: "Partner 131", + public: 'private', + state: 'open', + }); + const imSearchDef = makeDeferred(); + await this.start({ + async mockRPC(route, args) { + const res = await this._super(...arguments); + if (args.method === 'im_search') { + imSearchDef.resolve(); + } + return res; + }, + }); + + // open "new message" chat window + await afterNextRender(() => document.querySelector(`.o_MessagingMenu_toggler`).click()); + await afterNextRender(() => document.querySelector(`.o_MessagingMenu_newMessageButton`).click()); + + // search for a user in "new message" autocomplete + document.execCommand('insertText', false, "131"); + document.querySelector(`.o_ChatWindow_newMessageFormInput`) + .dispatchEvent(new window.KeyboardEvent('keydown')); + document.querySelector(`.o_ChatWindow_newMessageFormInput`) + .dispatchEvent(new window.KeyboardEvent('keyup')); + // Wait for search RPC to be resolved. The following await lines are + // necessary because autocomplete is an external lib therefore it is not + // possible to use `afterNextRender`. + await imSearchDef; + await nextAnimationFrame(); + const link = document.querySelector('.ui-autocomplete .ui-menu-item a'); + + await afterNextRender(() => link.click()); + assert.containsNone( + document.body, + '.o_ChatWindow_newMessageFormInput', + "'new message' chat window should not be there" + ); + assert.containsOnce( + document.body, + '.o_ChatWindow', + "should have only one chat window after selecting user whose chat is already open", + ); +}); + QUnit.test('new message autocomplete should automatically select first result', async function (assert) { assert.expect(1); diff --git a/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js b/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js index 958ce8f9652..ecfdaca5dfb 100644 --- a/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js +++ b/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js @@ -455,7 +455,10 @@ function factory(dependencies) { }), newMessageChatWindow: one2one('mail.chat_window', { compute: '_computeNewMessageChatWindow', - dependencies: ['allOrderedThread'], + dependencies: [ + 'allOrdered', + 'allOrderedThread', + ], }), unreadHiddenConversationAmount: attr({ compute: '_computeUnreadHiddenConversationAmount',