From 0cde1189c65e26e16c4f60a80a2c1a6f263aa226 Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Tue, 25 Aug 2020 12:38:46 +0000 Subject: [PATCH] [FIX] mail: chatwindow scroll to the last message when posting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when a user posted a message from a chatwindow, the scroll did not move to the last message. task-2314409 closes odoo/odoo#57183 X-original-commit: 8e4f133890b08e7e9a909abbc97b89bb5409119a Signed-off-by: Sébastien Theys (seb) Signed-off-by: Alexandre Kühn (aku) --- .../chat_window_manager_tests.js | 38 +++++++++++++++++++ .../static/src/models/composer/composer.js | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) 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 220f4278fa9..e2d049d6f87 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 @@ -1617,6 +1617,44 @@ QUnit.test('chat window with a thread: keep scroll position in message list on f ); }); +QUnit.test('chat window should scroll to the newly posted message just after posting it', async function (assert) { + assert.expect(1); + + this.data['mail.channel'].records.push({ + id: 20, + is_minimized: true, + state: 'open', + }); + for (let i = 0; i < 10; i++) { + this.data['mail.message'].records.push({ + channel_ids: [20], + model: 'mail.channel', + res_id: 20, + }); + } + await this.start(); + + // Set content of the composer of the chat window + await afterNextRender(() => { + document.querySelector('.o_ComposerTextInput_textarea').focus(); + document.execCommand('insertText', false, 'WOLOLO'); + }); + // Send a new message in the chatwindow to trigger the scroll + await afterNextRender(() => + triggerEvent( + document.querySelector('.o_ChatWindow .o_ComposerTextInput_textarea'), + 'keydown', + { key: 'Enter' }, + ) + ); + const messageList = document.querySelector('.o_MessageList'); + assert.strictEqual( + messageList.scrollHeight - messageList.scrollTop, + messageList.clientHeight, + "chat window should scroll to the newly posted message just after posting it" + ); +}); + QUnit.test('[technical] chat window: composer state conservation on toggle home menu when folded', async function (assert) { // technical as show/hide home menu simulation are involved and home menu implementation // have side-effects on DOM that may make chat window components not work diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js index 2be5919204b..d51f8c37249 100644 --- a/addons/mail/static/src/models/composer/composer.js +++ b/addons/mail/static/src/models/composer/composer.js @@ -182,7 +182,7 @@ function factory(dependencies) { thread.loadNewMessages(); } for (const threadView of this.thread.threadViews) { - threadView.addComponentHint('current-partner-just-posted-message', messageId); + threadView.addComponentHint('current-partner-just-posted-message', { messageId }); } this._reset(); }