Sort users

This commit is contained in:
Mattias Erming 2014-04-10 00:35:04 +02:00
parent 541e41e804
commit 7c3cf140d8
2 changed files with 14 additions and 6 deletions

View File

@ -220,7 +220,7 @@ $(function() {
var id = parseInt(link.closest(".window").attr("id").replace("window-", "")); var id = parseInt(link.closest(".window").attr("id").replace("window-", ""));
socket.emit("input", { socket.emit("input", {
id: id, id: id,
text: "/whois " + link.text(), text: "/whois " + link.text().trim(),
}); });
}); });

View File

@ -219,7 +219,9 @@ function event(event, data) {
case "join": case "join":
var chan = channels.findWhere({name: data[0].channel}) || channels.add({name: data[0].channel}); var chan = channels.findWhere({name: data[0].channel}) || channels.add({name: data[0].channel});
chan.addUser({name: data[0].nick}); var users = chan.get("users");
users.add({name: data[0].nick});
users.sort();
chan.addMessage({ chan.addMessage({
from: data[0].nick, from: data[0].nick,
type: "join", type: "join",
@ -271,11 +273,13 @@ function event(event, data) {
case "names": case "names":
var chan = channels.findWhere({name: data[0].channel}); var chan = channels.findWhere({name: data[0].channel});
chan.get("users").reset( var users = chan.get("users");
_.map(data[0].names, function(n) { users.reset(
return {name: n}; _.map(data[0].names, function(n) { return {name: n}; }),
}) {silent: true}
); );
users.sort();
users.trigger("reset", {}, users);
break; break;
case "nick": case "nick":
@ -292,6 +296,8 @@ function event(event, data) {
} }
user.set("name", data[0]["new"]); user.set("name", data[0]["new"]);
users.sort();
users.trigger("change", {}, users); users.trigger("change", {}, users);
chan.addMessage({ chan.addMessage({
@ -317,6 +323,7 @@ function event(event, data) {
} }
var users = chan.get("users"); var users = chan.get("users");
users.remove(users.findWhere({name: data[0].nick})); users.remove(users.findWhere({name: data[0].nick}));
users.sort();
chan.addMessage({ chan.addMessage({
from: data[0].nick, from: data[0].nick,
type: "part", type: "part",
@ -329,6 +336,7 @@ function event(event, data) {
var user = users.findWhere({name: data[0].nick}); var user = users.findWhere({name: data[0].nick});
if (user) { if (user) {
users.remove(user); users.remove(user);
users.sort();
chan.addMessage({ chan.addMessage({
from: data[0].nick, from: data[0].nick,
type: "quit", type: "quit",