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({