From 7c3cf140d84a00280260776ada11e635fd28b284 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Thu, 10 Apr 2014 00:35:04 +0200 Subject: [PATCH] Sort users --- client/js/chat.js | 2 +- lib/server.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client/js/chat.js b/client/js/chat.js index fe12c64..91a2c30 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -220,7 +220,7 @@ $(function() { var id = parseInt(link.closest(".window").attr("id").replace("window-", "")); socket.emit("input", { id: id, - text: "/whois " + link.text(), + text: "/whois " + link.text().trim(), }); }); diff --git a/lib/server.js b/lib/server.js index 7016bc0..bf4c826 100644 --- a/lib/server.js +++ b/lib/server.js @@ -219,7 +219,9 @@ function event(event, data) { case "join": 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({ from: data[0].nick, type: "join", @@ -271,11 +273,13 @@ function event(event, data) { case "names": var chan = channels.findWhere({name: data[0].channel}); - chan.get("users").reset( - _.map(data[0].names, function(n) { - return {name: n}; - }) + var users = chan.get("users"); + users.reset( + _.map(data[0].names, function(n) { return {name: n}; }), + {silent: true} ); + users.sort(); + users.trigger("reset", {}, users); break; case "nick": @@ -292,6 +296,8 @@ function event(event, data) { } user.set("name", data[0]["new"]); + + users.sort(); users.trigger("change", {}, users); chan.addMessage({ @@ -317,6 +323,7 @@ function event(event, data) { } var users = chan.get("users"); users.remove(users.findWhere({name: data[0].nick})); + users.sort(); chan.addMessage({ from: data[0].nick, type: "part", @@ -329,6 +336,7 @@ function event(event, data) { var user = users.findWhere({name: data[0].nick}); if (user) { users.remove(user); + users.sort(); chan.addMessage({ from: data[0].nick, type: "quit",