From bfba5ff33b3e317a0b6c41385a80464b4690b7f7 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 29 May 2019 12:22:18 +0200 Subject: [PATCH] Add chat scroll to bottom when opening it --- www/common/messenger-ui.js | 12 +++++++----- www/common/toolbar3.js | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/www/common/messenger-ui.js b/www/common/messenger-ui.js index ed9d88f18..bd77d80ff 100644 --- a/www/common/messenger-ui.js +++ b/www/common/messenger-ui.js @@ -197,6 +197,11 @@ define([ var getChat = function (id) { return $messages.find(dataQuery(id)); }; + + var scrollChatToBottom = function () { + var $messagebox = $('.cp-app-contacts-messages'); + $messagebox.scrollTop($messagebox[0].scrollHeight); + }; var normalizeLabels = function ($messagebox) { $messagebox.find('div.cp-app-contacts-message').toArray().reduce(function (a, b) { @@ -364,10 +369,7 @@ define([ input.value = ''; sending = false; debug('sent successfully'); - var $messagebox = $(messages); - - var height = $messagebox[0].scrollHeight; - $messagebox.scrollTop(height); + scrollChatToBottom(); }); }; @@ -584,7 +586,7 @@ define([ $messagebox.append(el_message); if (shouldScroll) { - $messagebox.scrollTop($messagebox[0].scrollHeight); + scrollChatToBottom(); } normalizeLabels($messagebox); reorderRooms(); diff --git a/www/common/toolbar3.js b/www/common/toolbar3.js index 6eb8d0596..3399b5fd3 100644 --- a/www/common/toolbar3.js +++ b/www/common/toolbar3.js @@ -486,6 +486,12 @@ MessengerUI, Messages) { var show = function () { if (Bar.isEmbed) { $content.hide(); return; } $content.show(); + // scroll down chat + var $messagebox = $content.find('.cp-app-contacts-messages'); + if ($messagebox.length) { + $messagebox.scrollTop($messagebox[0].scrollHeight); + } + $button.addClass('cp-toolbar-button-active'); config.$contentContainer.addClass('cp-chat-visible'); $button.removeClass('cp-toolbar-notification');