diff --git a/client/index.html b/client/index.html
index 2fe46968..4de8ce4f 100644
--- a/client/index.html
+++ b/client/index.html
@@ -68,7 +68,7 @@
{{#each users}}
{{/each}}
diff --git a/lib/models/chan.js b/lib/models/chan.js
index 8abfb5f4..3f5944fc 100644
--- a/lib/models/chan.js
+++ b/lib/models/chan.js
@@ -11,3 +11,19 @@ function Chan(attr) {
users: [],
}, attr));
};
+
+Chan.prototype = {
+ sortUsers: function() {
+ this.users = _.sortBy(
+ this.users,
+ function(u) { return u.name.toLowerCase(); }
+ );
+ var modes = ["+", "@"];
+ modes.forEach(function(mode) {
+ this.users = _.remove(
+ this.users,
+ function(u) { return u.mode == mode; }
+ ).concat(this.users);
+ }, this);
+ }
+};
diff --git a/lib/server.js b/lib/server.js
index 03d07536..fa10572f 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -264,6 +264,7 @@ function event(e, data) {
}
var users = chan.users;
users.push(new User({name: data.nick}));
+ chan.sortUsers();
sockets.emit("users", {
id: chan.id,
users: users,
@@ -309,6 +310,7 @@ function event(e, data) {
case "mode":
var chan = _.findWhere(channels, {name: data.target});
if (typeof chan !== "undefined") {
+ this.client.write("NAMES " + data.target);
var msg = new Msg({
type: "mode",
from: data.nick,
@@ -377,9 +379,13 @@ function event(e, data) {
break;
}
chan.users = [];
- data.names.forEach(function(n) {
- chan.users.push(new User({name: n}));
- });
+ for (var n in data.names) {
+ chan.users.push(new User({
+ mode: data.names[n],
+ name: n
+ }));
+ }
+ chan.sortUsers();
sockets.emit("users", {
id: chan.id,
users: chan.users,
@@ -405,6 +411,7 @@ function event(e, data) {
return;
}
user.name = data["new"];
+ chan.sortUsers();
sockets.emit("users", {
id: chan.id,
users: chan.users,
diff --git a/package.json b/package.json
index 59e34eb9..eb60b004 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
},
"dependencies": {
"lodash": "~2.4.1",
- "slate-irc": "~0.5.0",
+ "slate-irc": "https://github.com/erming/slate-irc/tarball/master",
"moment": "~2.5.1",
"connect": "~2.14.3",
"socket.io": "~0.9.16"