From 63828b95e0696a41c2e8d734ebea70c542a3e3e2 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 23 Feb 2018 18:21:42 +0200 Subject: [PATCH] Always correctly trigger sticky scroll on .chat container `.chat` has the overflow on it, and not `.messages` so stuff like scrollTop only works on `.chat` --- client/js/render.js | 2 +- client/js/renderPreview.js | 2 +- client/js/socket-events/msg.js | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/client/js/render.js b/client/js/render.js index 28920fb1..79809e01 100644 --- a/client/js/render.js +++ b/client/js/render.js @@ -217,7 +217,7 @@ function renderNetworks(data, singleNetwork) { container.find(".show-more").addClass("show"); } - container.trigger("keepToBottom"); + container.parent().trigger("keepToBottom"); } } else { newChannels.push(channel); diff --git a/client/js/renderPreview.js b/client/js/renderPreview.js index cfa42d01..cce42131 100644 --- a/client/js/renderPreview.js +++ b/client/js/renderPreview.js @@ -55,7 +55,7 @@ function appendPreview(preview, msg, template) { return; } - const container = msg.closest(".messages"); + const container = msg.closest(".chat"); const channelId = container.closest(".chan").data("id") || -1; const activeChannelId = chat.find(".chan.active").data("id") || -2; diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index 71967b33..2fbc6482 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -48,6 +48,7 @@ function processReceivedMessage(data) { } } + const scrollContainer = channel.find(".chat"); const container = channel.find(".messages"); const activeChannelId = chat.find(".chan.active").data("id"); @@ -64,7 +65,7 @@ function processReceivedMessage(data) { ); if (activeChannelId === targetId) { - container.trigger("keepToBottom"); + scrollContainer.trigger("keepToBottom"); } notifyMessage(targetId, channel, data); @@ -91,7 +92,7 @@ function processReceivedMessage(data) { if (activeChannelId !== targetId) { // If message arrives in non active channel, keep only 100 messages messageLimit = 100; - } else if (container.isScrollBottom()) { + } else if (scrollContainer.isScrollBottom()) { // If message arrives in active channel, keep 500 messages if scroll is currently at the bottom messageLimit = 500; }