Do not keep scroll to bottom in inactive channels

This commit is contained in:
Pavel Djundik 2017-11-23 19:33:19 +02:00
parent 7fb92fee64
commit 2f84b01427
2 changed files with 14 additions and 6 deletions

View File

@ -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 (activeChannelId === channelId) {
if (preview.shown && bottom) {
handleImageInPreview(msg.find(".toggle-content"), container);
}
container.trigger("keepToBottom");
}
}
$("#chat").on("click", ".text .toggle-button", function() {

View File

@ -46,7 +46,9 @@ function processReceivedMessage(data) {
data.msg
);
if (activeChannelId === targetId) {
container.trigger("keepToBottom");
}
notifyMessage(targetId, channel, data);