summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorPriyanka Kakadiya <pka@odoo.com>2021-02-05 05:03:39 +0000
committerPriyanka Kakadiya <pka@odoo.com>2021-02-12 12:20:09 +0000
commit016dedf172f750a0fcb1138a798faf2a224d513e (patch)
treea2c6392ae6e32d5b1276498690af0baefc033727 /addons
parent70f993e2209a1fd45d0ba938672295d79349febe (diff)
[FIX] mail: fix new message chatwindow issue
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#65851 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js55
-rw-r--r--addons/mail/static/src/models/chat_window_manager/chat_window_manager.js5
2 files changed, 59 insertions, 1 deletions
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 f06eb75bb17..45128a6774b 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 88fb24c1b1c..7fe8de75894 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
@@ -453,7 +453,10 @@ function factory(dependencies) {
}),
newMessageChatWindow: one2one('mail.chat_window', {
compute: '_computeNewMessageChatWindow',
- dependencies: ['allOrderedThread'],
+ dependencies: [
+ 'allOrdered',
+ 'allOrderedThread',
+ ],
}),
unreadHiddenConversationAmount: attr({
compute: '_computeUnreadHiddenConversationAmount',