Added user modes. Close #7

This commit is contained in:
Mattias Erming 2014-04-29 15:01:30 +02:00
parent b730e60582
commit bc534e9a04
4 changed files with 28 additions and 5 deletions

View File

@ -68,7 +68,7 @@
</div> </div>
{{#each users}} {{#each users}}
<button class="user"> <button class="user">
{{name}} {{mode}}{{name}}
</button> </button>
{{/each}} {{/each}}
</script> </script>

View File

@ -11,3 +11,19 @@ function Chan(attr) {
users: [], users: [],
}, attr)); }, 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);
}
};

View File

@ -264,6 +264,7 @@ function event(e, data) {
} }
var users = chan.users; var users = chan.users;
users.push(new User({name: data.nick})); users.push(new User({name: data.nick}));
chan.sortUsers();
sockets.emit("users", { sockets.emit("users", {
id: chan.id, id: chan.id,
users: users, users: users,
@ -309,6 +310,7 @@ function event(e, data) {
case "mode": case "mode":
var chan = _.findWhere(channels, {name: data.target}); var chan = _.findWhere(channels, {name: data.target});
if (typeof chan !== "undefined") { if (typeof chan !== "undefined") {
this.client.write("NAMES " + data.target);
var msg = new Msg({ var msg = new Msg({
type: "mode", type: "mode",
from: data.nick, from: data.nick,
@ -377,9 +379,13 @@ function event(e, data) {
break; break;
} }
chan.users = []; chan.users = [];
data.names.forEach(function(n) { for (var n in data.names) {
chan.users.push(new User({name: n})); chan.users.push(new User({
}); mode: data.names[n],
name: n
}));
}
chan.sortUsers();
sockets.emit("users", { sockets.emit("users", {
id: chan.id, id: chan.id,
users: chan.users, users: chan.users,
@ -405,6 +411,7 @@ function event(e, data) {
return; return;
} }
user.name = data["new"]; user.name = data["new"];
chan.sortUsers();
sockets.emit("users", { sockets.emit("users", {
id: chan.id, id: chan.id,
users: chan.users, users: chan.users,

View File

@ -8,7 +8,7 @@
}, },
"dependencies": { "dependencies": {
"lodash": "~2.4.1", "lodash": "~2.4.1",
"slate-irc": "~0.5.0", "slate-irc": "https://github.com/erming/slate-irc/tarball/master",
"moment": "~2.5.1", "moment": "~2.5.1",
"connect": "~2.14.3", "connect": "~2.14.3",
"socket.io": "~0.9.16" "socket.io": "~0.9.16"