diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-12-03 15:33:54 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-12-03 16:17:59 +0000 |
| commit | 7cdfe99d44a6df8c36556bfe6a17f5d9b96a8dd5 (patch) | |
| tree | f9eea0a5726e26e86228c205a7663ead930c638e /addons/mail/static/tests/thread_window | |
| parent | 3fd009a7a7c413a492bde07307ae6471dbc59105 (diff) | |
[FIX] mail: do not auto-focus new open chat window
Revision on https://github.com/odoo/odoo/commit/cd34f6de727d5b3858420cff3c9d3c5995c4e75c
Before this commit, when receiving a new message from a new DM
or livechat, the newly opened chat window was automatically
focused and marking messages as read.
Chat windows that are automatically opened without any user
interaction, such as when receiving a new message from a chat,
should not be focused. Those chat windows are "passive", and
the user must click on them in order to have focus and mark
messages as read (the chat window is no longer passive as a
result). The bug has been introduced by the refactoring from
the commit above.
In fact, there was a very short period of time during which the
chat window was passive. However, due to the way chat window
server-side state synchronization works, the chat window was
automatically closed then re-opened. This resulted in some visual
flickering of the chat window ('open' > 'close' > 'open'), and
the conversation was automatically marked as read. This was a
consequence of the actions 'open' > 'close' > 'open' that removed
the passive property of the chat window.
Chat window server-side synchronization relies on a notification
that tells the state of the conversation. Due to bad design, this
notification had exactly the same format as the one for notifying
all browser tabs of a newly joined conversation.
This commit fixes the issue by distinguishing "channel join"
and "chat window state" notification, so that the former is not
treated as a chat window notification. It fixes the problem
because it was precisely the "channel join" notification that caused
the chat window to close and loose its passive property.
Task-ID 1914735
opw-1914371
closes odoo/odoo#29223
Diffstat (limited to 'addons/mail/static/tests/thread_window')
| -rw-r--r-- | addons/mail/static/tests/thread_window/basic_thread_window_tests.js | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js index 8e454dced18..b749ae34963 100644 --- a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js +++ b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js @@ -522,6 +522,116 @@ QUnit.test('do not autofocus chat window on receiving new direct message', funct form.destroy(); }); +QUnit.test('do not auto-focus chat window on receiving new message from new DM', function (assert) { + assert.expect(10); + + var self = this; + this.data['mail.channel'] = { + fields: { + name: { + string: "Name", + type: "char", + required: true, + }, + channel_type: { + string: "Channel Type", + type: "selection", + }, + channel_message_ids: { + string: "Messages", + type: "many2many", + relation: 'mail.message' + }, + message_unread_counter: { + string: "Amount of Unread Messages", + type: "integer" + }, + }, + records: [{ + id: 2, + name: "DM", + channel_type: "chat", + message_unread_counter: 1, + direct_partner: [{ id: 666, name: 'DemoUser1', im_status: '' }], + is_minimized: false, + state: 'open', + }], + }; + + var parent = this.createParent({ + data: this.data, + services: this.services, + session: { partner_id: 3 }, + mockRPC: function (route, args) { + if (args.method === 'channel_join_and_get_info') { + return $.when(_.extend({}, self.data['mail.channel'].records[0], { info: 'join' })); + } + if (args.method === 'channel_minimize') { + _.extend(self.data['mail.channel'].records[0], { + is_minimized: true, + state: 'open', + }); + } + if (args.method === 'channel_seen') { + throw new Error('should not mark channel as seen'); + } + return this._super.apply(this, arguments); + } + }); + + assert.strictEqual($('.o_thread_window').length, 0, + "should not have any DM window open"); + + // simulate receiving message from someone else + var messageData = { + author_id: [5, "Someone else"], + body: "<p>Test message</p>", + id: 2, + model: 'mail.channel', + res_id: 2, + channel_ids: [2], + }; + this.data['mail.message'].records.push(messageData); + var notification = [[false, 'mail.channel', 2], messageData]; + parent.call('bus_service', 'trigger', 'notification', [notification]); + + assert.strictEqual($('.o_thread_window').length, 1, + "should have DM window open"); + assert.strictEqual($('.o_thread_window .o_input:focus').length, 0, + "thread window should not have the focus on auto-open"); + assert.ok($('.o_thread_window .o_thread_window_title').text().indexOf('(1)') !== -1, + "DM should display one unread message"); + + // simulate receiving join DM notification (cross-tab synchronization) + var dmInfo = _.extend({}, self.data['mail.channel'].records[0], { + info: 'join', + is_minimized: false, + state: 'open', + }); + notification = [[false, 'res.partner', 3], dmInfo]; + parent.call('bus_service', 'trigger', 'notification', [notification]); + + assert.strictEqual($('.o_thread_window').length, 1, + "should still have DM window open after receiving DM info from polling"); + assert.strictEqual($('.o_thread_window .o_input:focus').length, 0, + "thread window should still not have the focus after receiving DM info from polling"); + assert.ok($('.o_thread_window .o_thread_window_title').text().indexOf('(1)') !== -1, + "DM should still display one unread message after receiving DM info from polling"); + + // simulate receiving detached DM notification (cross-tab synchronization) + notification = [[false, 'res.partner', 3], self.data['mail.channel'].records[0]]; + parent.call('bus_service', 'trigger', 'notification', [notification]); + + assert.strictEqual($('.o_thread_window').length, 1, + "should still have DM open after receiving detached info from polling"); + assert.strictEqual($('.o_thread_window .o_input:focus').length, 0, + "thread window should still not have the focus after receiving detached info from polling"); + assert.ok($('.o_thread_window .o_thread_window_title').text().indexOf('(1)') !== -1, + "DM should not still have one unread message after receiving detached info from polling"); + + parent.destroy(); +}); + }); }); }); |
