From 9cc08d57e58368f9fa448aa4c7a2a14a6b085d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Thu, 26 Aug 2021 14:56:08 +0000 Subject: [PATCH] [FIX] mail: resolve issue with discuss app not considered opened MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `isOpen` is only written during mounted but it might happen that the discuss record is not yet created when the component is mounted. task-2632702 closes odoo/odoo#75655 Signed-off-by: Alexandre Kühn (aku) --- .../static/src/components/discuss/discuss.js | 16 +++------- .../components/discuss/tests/discuss_tests.js | 32 ++++++++++++++++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/addons/mail/static/src/components/discuss/discuss.js b/addons/mail/static/src/components/discuss/discuss.js index e85bea436cb..f565e18e208 100644 --- a/addons/mail/static/src/components/discuss/discuss.js +++ b/addons/mail/static/src/components/discuss/discuss.js @@ -2,6 +2,7 @@ import { registerMessagingComponent } from '@mail/utils/messaging_component'; import { link, unlink } from '@mail/model/model_field_command'; +import { useUpdate } from '@mail/component_hooks/use_update/use_update'; const { Component } = owl; const { useRef } = owl.hooks; @@ -24,28 +25,19 @@ export class Discuss extends Component { // bind since passed as props this._onMobileAddItemHeaderInputSelect = this._onMobileAddItemHeaderInputSelect.bind(this); this._onMobileAddItemHeaderInputSource = this._onMobileAddItemHeaderInputSource.bind(this); + useUpdate({ func: () => this._update() }); } - mounted() { + _update() { if (!this.discuss) { return; } this.discuss.update({ isOpen: true }); if (this.discuss.thread) { this.trigger('o-push-state-action-manager'); - } else if (this.discuss.messaging.isInitialized) { + } else if (!this._activeThreadCache && this.discuss.messaging.isInitialized) { this.discuss.openInitThread(); } - this._updateLocalStoreProps(); - } - - patched() { - if (!this.discuss) { - return; - } - if (this.discuss.thread) { - this.trigger('o-push-state-action-manager'); - } if ( this.discuss.thread && this.discuss.thread === this.messaging.inbox && 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 245d05c2847..d94b624ed81 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js @@ -23,14 +23,16 @@ QUnit.module('discuss_tests.js', { beforeEach(this); this.start = async params => { - const { afterEvent, env, widget } = await start(Object.assign({}, params, { + const res = await start(Object.assign({}, params, { autoOpenDiscuss: true, data: this.data, hasDiscuss: true, })); + const { afterEvent, env, widget } = res; this.afterEvent = afterEvent; this.env = env; this.widget = widget; + return res; }; }, afterEach() { @@ -50,6 +52,34 @@ QUnit.test('messaging not created', async function (assert) { messagingBeforeCreationDeferred.resolve(); }); +QUnit.test('discuss should be marked as opened if the component is already rendered and messaging becomes created afterwards', async function (assert) { + assert.expect(1); + + const messagingBeforeCreationDeferred = makeTestPromise(); + await this.start({ + messagingBeforeCreationDeferred, + waitUntilMessagingCondition: 'none', + }); + + await afterNextRender(() => messagingBeforeCreationDeferred.resolve()); + assert.ok( + this.messaging.discuss.isOpen, + "discuss should be marked as opened if the component is already rendered and messaging becomes created afterwards" + ); +}); + +QUnit.test('discuss should be marked as closed when the component is unmounted', async function (assert) { + assert.expect(1); + + const { widget } = await this.start(); + + await afterNextRender(() => widget.destroy()); + assert.notOk( + this.messaging.discuss.isOpen, + "discuss should be marked as closed when the component is unmounted" + ); +}); + QUnit.test('messaging not initialized', async function (assert) { assert.expect(1);