From 17b6674ca23aef657e8b67cc50b8633bebd2da17 Mon Sep 17 00:00:00 2001 From: Romain Estievenart Date: Wed, 16 Sep 2020 10:01:30 +0000 Subject: [PATCH] [FIX] mail: Mailbox is half loaded on mobile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit on mobile when you come to odoo from a notification url like: https://my_domain/web#action=mail.action_discuss&active_id=1&menu_id=93 a traceback occurs on mobile discuss wasn't loaded correctly and the content didn't appear. With this commit, it's open the related discuss thread. It's also ensure the return to the chat tab when you close a chat and the return to the channel tab when you close a channel conversation. We also ensure the loading of the inbox items when you navigating on the mobile discuss button. Steps to reproduce: 1. Open a chat from a mobile notification 2. A traceback occurs opw-2310319 closes odoo/odoo#58431 X-original-commit: 8ca5024bef246c93bbb7522d77aca4c4ba7a33b4 Signed-off-by: Alexandre Kühn (aku) --- .../components/discuss/tests/discuss_tests.js | 22 +++++++++++++ .../discuss_mobile_mailbox_selection_tests.js | 32 +++++++++++++++++++ .../mail/static/src/models/discuss/discuss.js | 31 ++++++++++++++++-- 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/components/discuss/tests/discuss_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_tests.js index bc97a8c004b..5308ac818ea 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js @@ -1246,6 +1246,28 @@ QUnit.test('load single message from channel initially', async function (assert) ); }); +QUnit.test('open channel from active_id as channel id', async function (assert) { + assert.expect(1); + + this.data['mail.channel'].records.push({ id: 20 }); + await this.start({ + discuss: { + context: { + active_id: 20, + }, + } + }); + assert.containsOnce( + document.body, + ` + .o_Discuss_thread[data-thread-local-id="${ + this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, model: 'mail.channel' }).localId + }"] + `, + "should have channel with ID 20 open in Discuss when providing active_id 20" + ); +}); + QUnit.test('basic rendering of message', async function (assert) { // AKU TODO: should be in message-only tests assert.expect(13); diff --git a/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection_tests.js b/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection_tests.js index 261d8c4bf54..0d145c13522 100644 --- a/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection_tests.js +++ b/addons/mail/static/src/components/discuss_mobile_mailbox_selection/discuss_mobile_mailbox_selection_tests.js @@ -91,6 +91,38 @@ QUnit.test('select another mailbox', async function (assert) { ); }); +QUnit.test('auto-select "Inbox" when discuss had channel as active thread', async function (assert) { + assert.expect(3); + + this.data['mail.channel'].records.push({ id: 20 }); + await this.start({ + discuss: { + context: { + active_id: 20, + }, + } + }); + assert.hasClass( + document.querySelector('.o_MobileMessagingNavbar_tab[data-tab-id="channel"]'), + 'o-active', + "'channel' tab should be active initially when loading discuss with channel id as active_id" + ); + + await afterNextRender(() => document.querySelector('.o_MobileMessagingNavbar_tab[data-tab-id="mailbox"]').click()); + assert.hasClass( + document.querySelector('.o_MobileMessagingNavbar_tab[data-tab-id="mailbox"]'), + 'o-active', + "'mailbox' tab should be selected after click on mailbox tab" + ); + assert.hasClass( + document.querySelector(`.o_DiscussMobileMailboxSelection_button[data-mailbox-local-id="${ + this.env.messaging.inbox.localId + }"]`), + 'o-active', + "'Inbox' mailbox should be auto-selected after click on mailbox tab" + ); +}); + }); }); }); diff --git a/addons/mail/static/src/models/discuss/discuss.js b/addons/mail/static/src/models/discuss/discuss.js index b05a08eea61..4bdc5e43549 100644 --- a/addons/mail/static/src/models/discuss/discuss.js +++ b/addons/mail/static/src/models/discuss/discuss.js @@ -151,7 +151,9 @@ function factory(dependencies) { * is not yet initialized. */ openInitThread() { - const [model, id] = this.initActiveId.split('_'); + const [model, id] = typeof this.initActiveId === 'number' + ? ['mail.channel', this.initActiveId] + : this.initActiveId.split('_'); const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: model !== 'mail.box' ? Number(id) : id, model, @@ -160,6 +162,9 @@ function factory(dependencies) { return; } thread.open(); + if (this.env.messaging.device.isMobile && thread.channel_type) { + this.update({ activeMobileNavbarTabId: thread.channel_type }); + } } @@ -324,6 +329,18 @@ function factory(dependencies) { */ _computeThread() { let thread = this.thread; + if (this.env.messaging && + this.env.messaging.inbox && + this.env.messaging.device.isMobile && + this.activeMobileNavbarTabId === 'mailbox' && + this.initActiveId !== 'mail.box_inbox' && + !thread + ) { + // After loading Discuss from an arbitrary tab other then 'mailbox', + // switching to 'mailbox' requires to also set its inner-tab ; + // by default the 'inbox'. + return [['replace', this.env.messaging.inbox]]; + } if (!thread || !thread.isPinned) { return [['unlink']]; } @@ -396,7 +413,9 @@ function factory(dependencies) { * Formatted init thread on opening discuss for the first time, * when no active thread is defined. Useful to set a thread to * open without knowing its local id in advance. - * format: _ + * Support two formats: + * {string} _ + * {int} with default model of 'mail.channel' */ initActiveId: attr({ default: 'mail.box_inbox', @@ -450,6 +469,9 @@ function factory(dependencies) { messaging: one2one('mail.messaging', { inverse: 'discuss', }), + messagingInbox: many2one('mail.thread', { + related: 'messaging.inbox', + }), renamingThreads: one2many('mail.thread'), /** * The message that is currently selected as being replied to in Inbox. @@ -497,8 +519,13 @@ function factory(dependencies) { thread: many2one('mail.thread', { compute: '_computeThread', dependencies: [ + 'activeMobileNavbarTabId', + 'deviceIsMobile', 'isThreadPinned', + 'messaging', + 'messagingInbox', 'thread', + 'threadModel', ], }), threadId: attr({