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

Only update the users list when needed #58

Merged
merged 1 commit into from Feb 19, 2016
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
18 changes: 18 additions & 0 deletions client/js/lounge.js
Expand Up @@ -394,6 +394,19 @@ $(function() {
});

socket.on("users", function(data) {
var chan = chat.find("#chan-" + data.chan);

if (chan.hasClass("active")) {
socket.emit("names", {
target: data.chan
});
}
else {
chan.data("needsNamesRefresh", true);
}
});

socket.on("names", function(data) {
var users = chat.find("#chan-" + data.chan).find(".users").html(render("user", data));
var nicks = [];
for (var i in data.users) {
Expand Down Expand Up @@ -572,6 +585,11 @@ $(function() {
}
}

if (chan.data("needsNamesRefresh") === true) {
chan.data("needsNamesRefresh", false);
socket.emit("names", {target: self.data("id")});
}

if (screen.width > 768 && chan.hasClass("chan")) {
input.focus();
}
Expand Down
13 changes: 13 additions & 0 deletions src/client.js
Expand Up @@ -303,6 +303,19 @@ Client.prototype.sort = function(data) {
}
};

Client.prototype.names = function(data) {
var client = this;
var target = client.find(data.target);
if (!target) {
return;
}

client.emit("names", {
chan: target.chan.id,
users: target.chan.users
});
};

Client.prototype.quit = function() {
var sockets = this.sockets.sockets;
var room = sockets.adapter.rooms[this.id] || [];
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/irc-events/join.js
Expand Up @@ -21,8 +21,7 @@ module.exports = function(irc, network) {
chan.users.push(new User({name: data.nick}));
chan.sortUsers();
client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});
var self = false;
if (data.nick.toLowerCase() === irc.me.toLowerCase()) {
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/irc-events/kick.js
Expand Up @@ -19,8 +19,7 @@ module.exports = function(irc, network) {
}

client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});

var self = false;
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/irc-events/names.js
Expand Up @@ -14,8 +14,7 @@ module.exports = function(irc, network) {
});
chan.sortUsers();
client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});
});
};
3 changes: 1 addition & 2 deletions src/plugins/irc-events/nick.js
Expand Up @@ -31,8 +31,7 @@ module.exports = function(irc, network) {
user.name = nick;
chan.sortUsers();
client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});
var msg = new Msg({
type: Msg.Type.NICK,
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/irc-events/part.js
Expand Up @@ -19,8 +19,7 @@ module.exports = function(irc, network) {
var user = _.findWhere(chan.users, {name: from});
chan.users = _.without(chan.users, user);
client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});
var reason = data.message || "";
if (reason.length > 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/irc-events/quit.js
Expand Up @@ -12,8 +12,7 @@ module.exports = function(irc, network) {
}
chan.users = _.without(chan.users, user);
client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});
var reason = data.message || "";
if (reason.length > 0) {
Expand Down
6 changes: 6 additions & 0 deletions src/server.js
Expand Up @@ -121,6 +121,12 @@ function init(socket, client, token) {
client.sort(data);
}
);
socket.on(
"names",
function(data) {
client.names(data);
}
);
socket.join(client.id);
socket.emit("init", {
active: client.activeChannel,
Expand Down