From 2f84b014278f37fc6f60fcc6232a0371f45adc2d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 23 Nov 2017 19:33:19 +0200 Subject: [PATCH] Do not keep scroll to bottom in inactive channels --- client/js/renderPreview.js | 16 +++++++++++----- client/js/socket-events/msg.js | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client/js/renderPreview.js b/client/js/renderPreview.js index 1ae515a0..c060e744 100644 --- a/client/js/renderPreview.js +++ b/client/js/renderPreview.js @@ -4,6 +4,7 @@ const $ = require("jquery"); const options = require("./options"); const socket = require("./socket"); const templates = require("../views"); +const chat = $("#chat"); const input = $("#input"); const Mousetrap = require("mousetrap"); @@ -29,8 +30,11 @@ function renderPreview(preview, msg) { preview.shown = preview.shown && options.shouldOpenMessagePreview(preview.type); const container = msg.closest(".chat"); + const channelId = container.data("id"); + const activeChannelId = chat.find(".chan.active").data("id"); + let bottom = false; - if (container.length) { + if (container.length && activeChannelId === channelId) { bottom = container.isScrollBottom(); } @@ -41,11 +45,13 @@ function renderPreview(preview, msg) { previewContainer .append(templates.msg_preview({preview: preview})); - if (preview.shown && bottom) { - handleImageInPreview(msg.find(".toggle-content"), container); - } + if (activeChannelId === channelId) { + if (preview.shown && bottom) { + handleImageInPreview(msg.find(".toggle-content"), container); + } - container.trigger("keepToBottom"); + container.trigger("keepToBottom"); + } } $("#chat").on("click", ".text .toggle-button", function() { diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index 889d491f..1a932398 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -46,7 +46,9 @@ function processReceivedMessage(data) { data.msg ); - container.trigger("keepToBottom"); + if (activeChannelId === targetId) { + container.trigger("keepToBottom"); + } notifyMessage(targetId, channel, data);