diff options
| author | Julien Giannone <jgi@odoo.com> | 2021-01-15 10:32:52 +0000 |
|---|---|---|
| committer | Julien Giannone <jgi@odoo.com> | 2021-02-12 10:08:57 +0000 |
| commit | a257e0ede12ead06c0f8dba90c3868761da6ea71 (patch) | |
| tree | 9a85656d593e6c152b66c284d0e2d04ba908e42e /addons/mail | |
| parent | 016dedf172f750a0fcb1138a798faf2a224d513e (diff) | |
[FIX] mail: (mobile) Prevent server sync for open/close state
This commit prevents the opening/closure of a channel on mobile when
the action is performed on desktop and reciprocally
closes odoo/odoo#64599
Tasks-id: 2267593
Related: odoo/enterprise#16296
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail')
5 files changed, 140 insertions, 10 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 45128a6774b..f3234bc5fc9 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 @@ -665,6 +665,121 @@ QUnit.test('chat window: open / close', async function (assert) { ); }); +QUnit.test('Mobile: opening a chat window should not update channel state on the server', async function (assert) { + assert.expect(2); + + this.data['mail.channel'].records.push({ + id: 20, + state: 'closed', + }); + await this.start({ + env: { + device: { + isMobile: true, + }, + }, + }); + await afterNextRender(() => document.querySelector(`.o_MessagingMenu_toggler`).click()); + await afterNextRender(() => document.querySelector(`.o_NotificationList_preview`).click()); + assert.containsOnce( + document.body, + '.o_ChatWindow', + "should have a chat window after clicking on thread preview" + ); + const channels = await this.env.services.rpc({ + model: 'mail.channel', + method: 'read', + args: [20], + }, { shadow: true }); + assert.strictEqual( + channels[0].state, + 'closed', + 'opening a chat window in mobile should not update channel state on the server', + ); +}); + +QUnit.test('Mobile: closing a chat window should not update channel state on the server', async function (assert) { + assert.expect(3); + + this.data['mail.channel'].records.push({ + id: 20, + state: 'open', + }); + await this.start({ + env: { + device: { + isMobile: true, + }, + }, + }); + await afterNextRender(() => document.querySelector(`.o_MessagingMenu_toggler`).click()); + await afterNextRender(() => document.querySelector(`.o_NotificationList_preview`).click()); + assert.containsOnce( + document.body, + '.o_ChatWindow', + "should have a chat window after clicking on thread preview" + ); + // Close chat window + await afterNextRender(() => document.querySelector(`.o_ChatWindowHeader_commandClose`).click()); + assert.containsNone( + document.body, + '.o_ChatWindow', + "should not have a chat window after closing it" + ); + const channels = await this.env.services.rpc({ + model: 'mail.channel', + method: 'read', + args: [20], + }, { shadow: true }); + assert.strictEqual( + channels[0].state, + 'open', + 'closing the chat window should not update channel state on the server', + ); +}); + +QUnit.test("Mobile: chat window shouldn't open automatically after receiving a new message", async function (assert) { + assert.expect(1); + + this.data['res.partner'].records.push({ id: 10, name: "Demo" }); + this.data['res.users'].records.push({ + id: 42, + partner_id: 10, + }); + this.data['mail.channel'].records = [ + { + channel_type: "chat", + id: 10, + members: [this.data.currentPartnerId, 10], + uuid: 'channel-10-uuid', + }, + ]; + await this.start({ + env: { + device: { + isMobile: true, + }, + }, + }); + + // simulate receiving a message + await afterNextRender(() => this.env.services.rpc({ + route: '/mail/chat_post', + params: { + context: { + mockedUserId: 42, + }, + message_content: "hu", + uuid: 'channel-10-uuid', + }, + })); + assert.containsNone( + document.body, + '.o_ChatWindow', + "On mobile, the chat window shouldn't open automatically after receiving a new message" + ); +}); + QUnit.test('chat window: close on ESCAPE', async function (assert) { assert.expect(10); diff --git a/addons/mail/static/src/models/chat_window/chat_window.js b/addons/mail/static/src/models/chat_window/chat_window.js index cf4b9442723..49e227428f5 100644 --- a/addons/mail/static/src/models/chat_window/chat_window.js +++ b/addons/mail/static/src/models/chat_window/chat_window.js @@ -39,9 +39,12 @@ function factory(dependencies) { * Close this chat window. * * @param {Object} [param0={}] - * @param {boolean} [param0.notifyServer=true] + * @param {boolean} [param0.notifyServer] */ - close({ notifyServer = true } = {}) { + close({ notifyServer } = {}) { + if (notifyServer === undefined) { + notifyServer = !this.env.messaging.device.isMobile; + } const thread = this.thread; this.delete(); // Flux specific: 'closed' fold state should only be saved on the @@ -89,9 +92,12 @@ function factory(dependencies) { /** * @param {Object} [param0={}] - * @param {boolean} [param0.notifyServer=true] + * @param {boolean} [param0.notifyServer] */ - fold({ notifyServer = true } = {}) { + fold({ notifyServer } = {}) { + if (notifyServer === undefined) { + notifyServer = !this.env.messaging.device.isMobile; + } this.update({ isFolded: true }); // Flux specific: manually folding the chat window should save the // new state on the server. @@ -140,9 +146,12 @@ function factory(dependencies) { /** * @param {Object} [param0={}] - * @param {boolean} [param0.notifyServer=true] + * @param {boolean} [param0.notifyServer] */ - unfold({ notifyServer = true } = {}) { + unfold({ notifyServer } = {}) { + if (notifyServer === undefined) { + notifyServer = !this.env.messaging.device.isMobile; + } this.update({ isFolded: false }); // Flux specific: manually opening the chat window should save the // new state on the server. 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 7fe8de75894..fc367fef552 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 @@ -103,15 +103,18 @@ function factory(dependencies) { * @param {Object} [param1={}] * @param {boolean} [param1.isFolded=false] * @param {boolean} [param1.makeActive=false] - * @param {boolean} [param1.notifyServer=true] + * @param {boolean} [param1.notifyServer] * @param {boolean} [param1.replaceNewMessage=false] */ openThread(thread, { isFolded = false, makeActive = false, - notifyServer = true, + notifyServer, replaceNewMessage = false } = {}) { + if (notifyServer === undefined) { + notifyServer = !this.env.messaging.device.isMobile; + } let chatWindow = this.chatWindows.find(chatWindow => chatWindow.thread === thread ); diff --git a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js index a63acfb82fe..5457ed989ff 100644 --- a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js @@ -267,7 +267,7 @@ function factory(dependencies) { channel.markAsFetched(); } // (re)open chat on receiving new message - if (channel.channel_type !== 'channel') { + if (channel.channel_type !== 'channel' && !this.env.messaging.device.isMobile) { this.env.messaging.chatWindowManager.openThread(channel); } } @@ -708,7 +708,7 @@ function factory(dependencies) { const chat = await this.async(() => this.env.messaging.getChat({ partnerId: partner_id } )); - if (!chat) { + if (!chat || this.env.messaging.device.isMobile) { return; } this.env.messaging.chatWindowManager.openThread(chat); diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index 0446baa9f8e..31339e063f3 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -1546,6 +1546,9 @@ function factory(dependencies) { // avoid crash during destroy return; } + if (this.env.messaging.device.isMobile) { + return; + } if (this.serverFoldState === 'closed') { this.env.messaging.chatWindowManager.closeThread(this, { notifyServer: false, |
