summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/components/message_list
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-09-29 18:50:23 +0000
committerSébastien Theys <seb@odoo.com>2020-09-29 19:47:12 +0000
commitfb9b1c8a169840951925fa810f71e865a54e3a31 (patch)
tree591c34b02dfdde95ebaf296db7abfee5614e22ea /addons/mail/static/src/components/message_list
parentb4783500db5b7c645859227e8be5cd55025b2882 (diff)
[FIX] mail: reintroduce auto scroll on receiving message
task-2336251 closes odoo/odoo#58867 X-original-commit: f732980b2e5e83bcf2fdc8d3ce756f256cacbd4f Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components/message_list')
-rw-r--r--addons/mail/static/src/components/message_list/message_list.js63
1 files changed, 43 insertions, 20 deletions
diff --git a/addons/mail/static/src/components/message_list/message_list.js b/addons/mail/static/src/components/message_list/message_list.js
index bc1ab67bbfc..72368ec3689 100644
--- a/addons/mail/static/src/components/message_list/message_list.js
+++ b/addons/mail/static/src/components/message_list/message_list.js
@@ -118,15 +118,15 @@ class MessageList extends Component {
case 'change-of-thread-cache':
this._adjustFromChangeOfThreadCache(hint);
break;
- case 'current-partner-just-posted-message':
- this._adjustFromCurrentPartnerJustPostedMessage(hint);
- break;
case 'home-menu-hidden':
this._adjustFromHomeMenuHidden(hint);
break;
case 'home-menu-shown':
this._adjustFromHomeMenuShown(hint);
break;
+ case 'message-received':
+ this._adjustFromMessageReceived(hint);
+ break;
case 'more-messages-loaded':
this._adjustFromMoreMessagesLoaded(hint);
break;
@@ -352,28 +352,17 @@ class MessageList extends Component {
/**
* @private
* @param {Object} hint
- * @param {Object} hint.data
- * @param {integer} hint.data.messageId
*/
- async _adjustFromCurrentPartnerJustPostedMessage(hint) {
- const threadCache = this.threadView.threadCache;
- if (threadCache.isLoaded && hint.data) {
- const { messageId } = hint.data;
- const threadCacheMessageIds = threadCache.messages.map(message => message.id);
- if (threadCacheMessageIds.includes(messageId) && this.messageRefFromId(messageId)) {
- if (this.props.hasScrollAdjust) {
- await this._scrollToMessage(messageId);
- }
- this.threadView.markComponentHintProcessed(hint);
- }
- }
+ _adjustFromHomeMenuHidden(hint) {
+ this._adjustScrollFromModel();
+ this.threadView.markComponentHintProcessed(hint);
}
/**
* @private
* @param {Object} hint
*/
- _adjustFromHomeMenuHidden(hint) {
+ _adjustFromHomeMenuShown(hint) {
this._adjustScrollFromModel();
this.threadView.markComponentHintProcessed(hint);
}
@@ -382,8 +371,34 @@ class MessageList extends Component {
* @private
* @param {Object} hint
*/
- _adjustFromHomeMenuShown(hint) {
- this._adjustScrollFromModel();
+ async _adjustFromMessageReceived(hint) {
+ const threadCache = this.threadView.threadCache;
+ if (!threadCache.isLoaded) {
+ return;
+ }
+ const { message } = hint.data;
+ if (!threadCache.messages.includes(message)) {
+ return;
+ }
+ if (!this.messageRefFromId(message.id)) {
+ return;
+ }
+ if (!this.props.hasScrollAdjust) {
+ this.threadView.markComponentHintProcessed(hint);
+ return;
+ }
+ if (!this.threadView.hasAutoScrollOnMessageReceived) {
+ this.threadView.markComponentHintProcessed(hint);
+ return;
+ }
+ if (
+ this.threadView.lastVisibleMessage &&
+ (message.id < this.threadView.lastVisibleMessage.id)
+ ) {
+ this.threadView.markComponentHintProcessed(hint);
+ return;
+ }
+ await this._scrollToMessage(message.id);
this.threadView.markComponentHintProcessed(hint);
}
@@ -537,6 +552,14 @@ class MessageList extends Component {
scrollTop,
threadViewer: this.threadView.threadViewer,
});
+ // Margin to compensate for inaccurate scrolling to bottom.
+ const margin = 4;
+ // Automatically scroll to new received messages only when the list is
+ // currently fully scrolled.
+ const hasAutoScrollOnMessageReceived = (this.props.order === 'asc')
+ ? scrollTop >= this.el.scrollHeight - this.el.clientHeight - margin
+ : scrollTop <= margin;
+ this.threadView.update({ hasAutoScrollOnMessageReceived });
this.threadView.threadViewer.saveThreadCacheScrollPositionsAsInitial(scrollTop);
if (!this._isAutoLoadOnScrollActive) {
return;