From e5ce2f2688de9895b674d64d8f1b26be663c3c22 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 13 Aug 2017 12:23:51 +0300 Subject: [PATCH] Remove 10 second interval to trim buffer Fixes #96 --- client/js/lounge.js | 17 ----------------- client/js/socket-events/msg.js | 22 +++++++++++++++++++--- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 888b24c7..9d0d1363 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -909,23 +909,6 @@ $(function() { } }()); - setInterval(function() { - chat.find(".chan:not(.active)").each(function() { - var chan = $(this); - if (chan.find(".messages .msg").slice(0, -100).remove().length) { - chan.find(".show-more").addClass("show"); - - // Remove date-seperators that would otherwise be "stuck" at the top - // of the channel - chan.find(".date-marker-container").each(function() { - if ($(this).next().hasClass("date-marker-container")) { - $(this).remove(); - } - }); - } - }); - }, 1000 * 10); - function completeNicks(word) { const users = chat.find(".active .users"); diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index df3dc35e..15764848 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -8,8 +8,11 @@ const templates = require("../../views"); socket.on("msg", function(data) { const msg = render.buildChatMessage(data); - const target = "#chan-" + data.chan; - const container = chat.find(target + " .messages"); + const target = data.chan; + const channel = chat.find("#chan-" + target); + const container = channel.find(".messages"); + + const activeChannelId = chat.find(".chan.active").data("id"); if (data.msg.type === "channel_list" || data.msg.type === "ban_list") { $(container).empty(); @@ -33,7 +36,7 @@ socket.on("msg", function(data) { container .append(msg) .trigger("msg", [ - target, + "#chan-" + target, data ]) .trigger("keepToBottom"); @@ -47,4 +50,17 @@ socket.on("msg", function(data) { .find(".unread-marker") .appendTo(container); } + + // Message arrived in a non active channel, trim it to 100 messages + if (activeChannelId !== target && container.find(".msg").slice(0, -100).remove().length) { + channel.find(".show-more").addClass("show"); + + // Remove date-seperators that would otherwise + // be "stuck" at the top of the channel + channel.find(".date-marker-container").each(function() { + if ($(this).next().hasClass("date-marker-container")) { + $(this).remove(); + } + }); + } });