Merge pull request #58 from maxpoulin64/userlist-lag

Only update the users list when needed
This commit is contained in:
Alistair McKinlay 2016-02-19 21:24:09 +00:00
commit 972aadd674
9 changed files with 43 additions and 12 deletions

View File

@ -395,6 +395,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) {
@ -573,6 +586,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();
}

View File

@ -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] || [];

View File

@ -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()) {

View File

@ -19,8 +19,7 @@ module.exports = function(irc, network) {
}
client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});
var self = false;

View File

@ -14,8 +14,7 @@ module.exports = function(irc, network) {
});
chan.sortUsers();
client.emit("users", {
chan: chan.id,
users: chan.users
chan: chan.id
});
});
};

View File

@ -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,

View File

@ -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) {

View File

@ -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) {

View File

@ -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,