From df30f9fba325ee17ec68958c3d34aa25600fb81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 23 Mar 2022 16:10:40 +0000 Subject: [PATCH] [FIX] mail: reintroduce scroll to top on posting message in chatter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The feature was broken in https://github.com/odoo/odoo/commit/80d74e7ee0eab83dc5100e0776df09d04b882fec#diff-14904a101d1c0589d79515df7065aeeaaf0d4cdeaff9a4748ff0331c481efe8eL275 where `loadNewMessages` was mistakenly removed. But this call is useful to make sure newly posted messages (from other users) are fetched, as well as having the side-effect to scroll to the newly posted message of the current user in particular. closes odoo/odoo#87114 X-original-commit: 1550e08945597f3a49a7c8adec3cc0c2d9afdf82 Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Sébastien Theys (seb) --- .../mail/static/src/components/message_list/message_list.js | 1 + addons/mail/static/src/models/composer_view.js | 4 +++- addons/mail/static/src/models/thread_cache.js | 2 +- 3 files changed, 5 insertions(+), 2 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 224d3a65c3a..650b2e2e1a3 100644 --- a/addons/mail/static/src/components/message_list/message_list.js +++ b/addons/mail/static/src/components/message_list/message_list.js @@ -106,6 +106,7 @@ export class MessageList extends Component { // saved position if it exists or scroll to the end this._adjustScrollFromModel(); break; + case 'message-posted': case 'message-received': case 'messages-loaded': case 'new-messages-loaded': diff --git a/addons/mail/static/src/models/composer_view.js b/addons/mail/static/src/models/composer_view.js index 35a24c018df..76473c095b4 100644 --- a/addons/mail/static/src/models/composer_view.js +++ b/addons/mail/static/src/models/composer_view.js @@ -369,13 +369,15 @@ registerModel({ for (const threadView of message.originThread.threadViews) { // Reset auto scroll to be able to see the newly posted message. threadView.update({ hasAutoScrollOnMessageReceived: true }); + threadView.addComponentHint('message-posted', { message }); } if (chatterThread) { if (this.exists()) { this.delete(); } if (chatterThread.exists()) { - chatterThread.fetchData(['followers', 'suggestedRecipients']); + // Load new messages to fetch potential new messages from other users (useful due to lack of auto-sync in chatter). + chatterThread.fetchData(['followers', 'messages', 'suggestedRecipients']); } } if (threadViewThread) { diff --git a/addons/mail/static/src/models/thread_cache.js b/addons/mail/static/src/models/thread_cache.js index 1b480e49ae8..8ad1553c8c3 100644 --- a/addons/mail/static/src/models/thread_cache.js +++ b/addons/mail/static/src/models/thread_cache.js @@ -54,7 +54,7 @@ registerModel({ } const messageIds = this.fetchedMessages.map(message => message.id); const fetchedMessages = this._loadMessages({ minId: Math.max(...messageIds) }); - if (!fetchedMessages) { + if (!fetchedMessages || fetchedMessages.length === 0) { return; } for (const threadView of this.threadViews) {