summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/components/chat_window
diff options
context:
space:
mode:
authorXavier Dubuc <xdu@odoo.com>2020-09-03 16:24:19 +0000
committerSébastien Theys <seb@odoo.com>2020-09-04 14:59:01 +0000
commit8d3413ff647de8d98c6858062dd07dde4160af95 (patch)
tree3dc134e83c874d5c7f7bf739f13a88ab986ddb1b /addons/mail/static/src/components/chat_window
parenta5ab687be4e7890262ce9429e18dd011021513d5 (diff)
[FIX] mail, sms, snailmail: prevent message_fetch for hidden threads
Automatically load messages from a thread cache only if the thread cache is used in at least one thread view. Ensure thread viewer don't keep thread view records alive when they are not displayed. This change is particularly important for performance, to avoid spamming RPC at init if many threads are opened in chat windows. task-2310623 closes odoo/odoo#57061 X-original-commit: dd6981c7812134e0588f80a157eaba45512cd68e Related: odoo/enterprise#12936 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components/chat_window')
-rw-r--r--addons/mail/static/src/components/chat_window/chat_window.js31
-rw-r--r--addons/mail/static/src/components/chat_window/chat_window.xml54
2 files changed, 36 insertions, 49 deletions
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"
/>
- <t t-if="!chatWindow.isFolded">
- <t t-if="chatWindow.thread">
- <ThreadView
- class="o_ChatWindow_thread"
- composerAttachmentsDetailsMode="'card'"
- hasComposer="chatWindow.thread.model !== 'mail.box' and (!chatWindow.thread.mass_mailing or env.messaging.device.isMobile)"
- hasComposerCurrentPartnerAvatar="false"
- hasComposerSendButton="env.messaging.device.isMobile"
- hasSquashCloseMessages="chatWindow.thread.model !== 'mail.box'"
- threadViewLocalId="chatWindow.threadView.localId"
- t-on-focusin="_onFocusinThread"
- t-ref="thread"
+ <t t-if="chatWindow.threadView">
+ <ThreadView
+ class="o_ChatWindow_thread"
+ composerAttachmentsDetailsMode="'card'"
+ hasComposer="chatWindow.thread.model !== 'mail.box' and (!chatWindow.thread.mass_mailing or env.messaging.device.isMobile)"
+ hasComposerCurrentPartnerAvatar="false"
+ hasComposerSendButton="env.messaging.device.isMobile"
+ hasSquashCloseMessages="chatWindow.thread.model !== 'mail.box'"
+ threadViewLocalId="chatWindow.threadView.localId"
+ t-on-focusin="_onFocusinThread"
+ t-ref="thread"
+ />
+ </t>
+ <t t-if="chatWindow.hasNewMessageForm">
+ <div class="o_ChatWindow_newMessageForm">
+ <span class="o_ChatWindow_newMessageFormLabel">
+ To:
+ </span>
+ <AutocompleteInput
+ class="o_ChatWindow_newMessageFormInput"
+ isHtml="true"
+ placeholder="newMessageFormInputPlaceholder"
+ select="_onAutocompleteSelect"
+ source="_onAutocompleteSource"
+ t-ref="input"
/>
- </t>
- <t t-else="">
- <div class="o_ChatWindow_newMessageForm">
- <span class="o_ChatWindow_newMessageFormLabel">
- To:
- </span>
- <AutocompleteInput
- class="o_ChatWindow_newMessageFormInput"
- isHtml="true"
- placeholder="newMessageFormInputPlaceholder"
- select="_onAutocompleteSelect"
- source="_onAutocompleteSource"
- t-ref="input"
- />
- </div>
- </t>
+ </div>
</t>
</t>
</div>