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

View file

@ -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();
}
});
}
});