diff --git a/addons/mail/static/src/components/chat_window/chat_window.js b/addons/mail/static/src/components/chat_window/chat_window.js index 43353c6086f..a5d0b2c9a20 100644 --- a/addons/mail/static/src/components/chat_window/chat_window.js +++ b/addons/mail/static/src/components/chat_window/chat_window.js @@ -115,12 +115,10 @@ class ChatWindow extends Component { isDoFocus: false, isFocused: true, }); - if (this.chatWindow.isFolded) { - return; - } - if (!this.chatWindow.thread) { + if (this._inputRef.comp) { this._inputRef.comp.focus(); - } else { + } + if (this._threadRef.comp) { this._threadRef.comp.focus(); } } @@ -134,7 +132,10 @@ class ChatWindow extends Component { * @private */ _saveThreadScrollTop() { - this.chatWindow.threadView.saveThreadCacheScrollPositionsAsInitial( + if (!this._threadRef.comp || !this.chatWindow.threadViewer) { + return; + } + this.chatWindow.threadViewer.saveThreadCacheScrollPositionsAsInitial( this._threadRef.comp.getScrollTop() ); } @@ -248,9 +249,7 @@ class ChatWindow extends Component { this.chatWindow.unfold(); this.chatWindow.focus(); } else { - if (this.chatWindow.thread) { - this._saveThreadScrollTop(); - } + this._saveThreadScrollTop(); this.chatWindow.fold(); } } @@ -336,12 +335,7 @@ class ChatWindow extends Component { * @private */ async _onWillHideHomeMenu() { - if (!this.chatWindow.thread) { - return; - } - if (!this.chatWindow.isFolded) { - this._saveThreadScrollTop(); - } + this._saveThreadScrollTop(); } /** @@ -353,12 +347,7 @@ class ChatWindow extends Component { * @private */ async _onWillShowHomeMenu() { - if (!this.chatWindow.thread) { - return; - } - if (!this.chatWindow.isFolded) { - this._saveThreadScrollTop(); - } + this._saveThreadScrollTop(); } } diff --git a/addons/mail/static/src/components/chat_window/chat_window.xml b/addons/mail/static/src/components/chat_window/chat_window.xml index f92a32cf2fe..240cf0f974c 100644 --- a/addons/mail/static/src/components/chat_window/chat_window.xml +++ b/addons/mail/static/src/components/chat_window/chat_window.xml @@ -20,35 +20,33 @@ t-on-o-clicked="_onClickedHeader" t-ref="header" /> - - - + + + +
+ + To: + + - - -
- - To: - - -
-
+
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 efba64cecde..220f4278fa9 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 @@ -1753,6 +1753,122 @@ QUnit.test('[technical] chat window with a thread: keep scroll position in messa ); }); +QUnit.test('chat window does not fetch messages if hidden', async function (assert) { + /** + * computation uses following info: + * ([mocked] global window width: 900px) + * (others: @see `mail/static/src/models/chat_window_manager/chat_window_manager.js:visual`) + * + * - chat window width: 325px + * - start/end/between gap width: 10px/10px/5px + * - hidden menu width: 200px + * - global width: 1080px + * + * Enough space for 2 visible chat windows, and one hidden chat window: + * 3 visible chat windows: + * 10 + 325 + 5 + 325 + 5 + 325 + 10 = 1000 > 900 + * 2 visible chat windows + hidden menu: + * 10 + 325 + 5 + 325 + 10 + 200 + 5 = 875 < 900 + */ + assert.expect(14); + + // 3 channels are expected to be found in the messaging menu, each with a + // random unique id that will be referenced in the test + this.data['mail.channel'].records = [ + { + id: 10, + is_minimized: true, + name: "Channel #10", + state: 'open', + }, + { + id: 11, + is_minimized: true, + name: "Channel #11", + state: 'open', + }, + { + id: 12, + is_minimized: true, + name: "Channel #12", + state: 'open', + }, + ]; + await this.start({ + env: { + browser: { + innerWidth: 900, + }, + }, + mockRPC(route, args) { + if (args.method === 'message_fetch') { + // domain should be like [['channel_id', 'in', [X]]] with X the channel id + const channel_ids = args.kwargs.domain[0][2]; + assert.strictEqual(channel_ids.length, 1, "messages should be fetched channel per channel"); + assert.step(`rpc:message_fetch:${channel_ids[0]}`); + } + return this._super(...arguments); + }, + }); + + assert.containsN( + document.body, + '.o_ChatWindow', + 2, + "2 chat windows should be visible" + ); + assert.containsNone( + document.body, + `.o_ChatWindow[data-thread-local-id="${ + this.env.models['mail.thread'].find(t => + t.model === 'mail.channel' && t.id === 12 + ).localId + }"]`, + "chat window for Channel #12 should be hidden" + ); + assert.containsOnce( + document.body, + '.o_ChatWindowHiddenMenu', + "chat window hidden menu should be displayed" + ); + assert.verifySteps( + ['rpc:message_fetch:10', 'rpc:message_fetch:11'], + "messages should be fetched for the two visible chat windows" + ); + + await afterNextRender(() => + document.querySelector('.o_ChatWindowHiddenMenu_dropdownToggle').click() + ); + assert.containsOnce( + document.body, + '.o_ChatWindowHiddenMenu_chatWindowHeader', + "1 hidden chat window should be listed in hidden menu" + ); + + await afterNextRender(() => + document.querySelector('.o_ChatWindowHiddenMenu_chatWindowHeader').click() + ); + assert.containsN( + document.body, + '.o_ChatWindow', + 2, + "2 chat windows should still be visible" + ); + assert.containsOnce( + document.body, + `.o_ChatWindow[data-thread-local-id="${ + this.env.models['mail.thread'].find(t => + t.model === 'mail.channel' && t.id === 12 + ).localId + }"]`, + "chat window for Channel #12 should now be visible" + ); + assert.verifySteps( + ['rpc:message_fetch:12'], + "messages should now be fetched for Channel #12" + ); +}); + }); }); }); diff --git a/addons/mail/static/src/components/chatter/chatter.xml b/addons/mail/static/src/components/chatter/chatter.xml index e5601dd7974..53550da516d 100644 --- a/addons/mail/static/src/components/chatter/chatter.xml +++ b/addons/mail/static/src/components/chatter/chatter.xml @@ -8,7 +8,7 @@ class="o_Chatter_topbar" chatterLocalId="chatter.localId" /> - + - - - - - - - + + + + + diff --git a/addons/mail/static/src/components/chatter_topbar/chatter_topbar.xml b/addons/mail/static/src/components/chatter_topbar/chatter_topbar.xml index 3512f93332e..6911dfb959e 100644 --- a/addons/mail/static/src/components/chatter_topbar/chatter_topbar.xml +++ b/addons/mail/static/src/components/chatter_topbar/chatter_topbar.xml @@ -5,7 +5,7 @@
- +