diff --git a/client/js/lounge.js b/client/js/lounge.js index 888b24c793..9d0d136352 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 df3dc35ef4..157648481b 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(); + } + }); + } });