Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 10-second interval to trim buffer #1409

Merged
merged 1 commit into from Aug 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth putting this in a debounce function so it doesn't fire more than once every N seconds (10?)? I'm concerned this could be called a lot in very active channels.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you wanna look into it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the channel:

<xPaw>     astorije, I remember testing the message trimmer in my queue PR on twitch channels
<astorije> So you're saying no debounce needed, right?
<xPaw>     it produced like multiple new message per seconds, and while debugging it, I saw nothing that pointed towards this code
<xPaw>     so yes, shouldnt be needed

});