Skip to content

Commit

Permalink
Merge pull request #1409 from thelounge/xpaw/show-more-trim
Browse files Browse the repository at this point in the history
Remove 10 second interval to trim buffer
  • Loading branch information
astorije committed Aug 13, 2017
2 parents 16cde4f + e5ce2f2 commit d876624
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
17 changes: 0 additions & 17 deletions client/js/lounge.js
Expand Up @@ -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");

Expand Down
22 changes: 19 additions & 3 deletions client/js/socket-events/msg.js
Expand Up @@ -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();
Expand All @@ -33,7 +36,7 @@ socket.on("msg", function(data) {
container
.append(msg)
.trigger("msg", [
target,
"#chan-" + target,
data
])
.trigger("keepToBottom");
Expand All @@ -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();
}
});
}
});

0 comments on commit d876624

Please sign in to comment.