Remove 10 second interval to trim buffer

Fixes #96
This commit is contained in:
Pavel Djundik 2017-08-13 12:23:51 +03:00
parent d39e8ba9f8
commit e5ce2f2688
2 changed files with 19 additions and 20 deletions

View File

@ -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) { function completeNicks(word) {
const users = chat.find(".active .users"); const users = chat.find(".active .users");

View File

@ -8,8 +8,11 @@ const templates = require("../../views");
socket.on("msg", function(data) { socket.on("msg", function(data) {
const msg = render.buildChatMessage(data); const msg = render.buildChatMessage(data);
const target = "#chan-" + data.chan; const target = data.chan;
const container = chat.find(target + " .messages"); 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") { if (data.msg.type === "channel_list" || data.msg.type === "ban_list") {
$(container).empty(); $(container).empty();
@ -33,7 +36,7 @@ socket.on("msg", function(data) {
container container
.append(msg) .append(msg)
.trigger("msg", [ .trigger("msg", [
target, "#chan-" + target,
data data
]) ])
.trigger("keepToBottom"); .trigger("keepToBottom");
@ -47,4 +50,17 @@ socket.on("msg", function(data) {
.find(".unread-marker") .find(".unread-marker")
.appendTo(container); .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();
}
});
}
}); });