Implemented NAMES events

This commit is contained in:
Mattias Erming 2014-03-12 19:06:08 +01:00
parent 62a40246a9
commit a4a3499a54
5 changed files with 43 additions and 17 deletions

View file

@ -108,11 +108,12 @@ h2 {
}
#chat .users {
border-left: 1px solid #ccc;
float: right;
height: 100%;
margin-top: 36px;
bottom: 26px;
overflow-y: auto;
padding-top: 6px;
padding: 4px 0;
position: absolute;
right: 0px;
top: 36px;
width: 159px;
}
#chat .users .user {
@ -125,7 +126,7 @@ h2 {
bottom: 26px;
left: 0;
overflow-y: auto;
padding: 6px 0;
padding: 4px 0;
position: absolute;
right: 160px;
top: 36px;

View file

@ -42,7 +42,7 @@
<script type="text/html" id="users">
{{#users}}
<div class="user" data-id="{{id}}">
<div class="user">
{{mode}}{{name}}
</div>
{{/users}}

View file

@ -56,7 +56,6 @@ $(function() {
case "users":
target = target.find(".users");
target.html(Mustache.render(users, {users: data.data}));
console.log("RENDER USERS");
break;
case "messages":

View file

@ -11,7 +11,7 @@ var id = 1;
models.User = Backbone.Model.extend({
defaults: {
mode: "",
name: "user"
name: ""
}
});

View file

@ -84,6 +84,13 @@ function handleInput(input) {
}
break;
case "NAMES":
var irc = target.network.irc;
if (argv[1] && typeof irc !== "undefined") {
irc.send("NAMES", argv[1]);
}
break;
case "SERVER":
case "CONNECT":
if (argv[1]) {
@ -130,16 +137,10 @@ function handleEvent(argv) {
case "JOIN":
if (argv.nick == network.get("nick")) {
var channel = new models.Channel({
name: argv.args[0]
});
channel.get("users").add(
new models.User({
name: network.get("nick")
})
)
channels.add(
channel
new models.Channel({
name: argv.args[0]
})
);
} else {
var channel = channels.findWhere({name: argv.args[0]});
@ -179,6 +180,31 @@ function handleEvent(argv) {
);
}
break;
case "rpl_namreply":
var names = argv.args[3].split(' ');
var channel = network.get("channels").findWhere({name: argv.args[2]});
var users = channel.get("users");
if (names[0] == network.get("nick")) {
users.reset();
}
for (var i in names) {
users.add(
new models.User({name: names[i]}), {
silent: true
}
);
}
break;
case "rpl_endofnames":
var channel = network.get("channels").findWhere({name: argv.args[1]});
var users = channel.get("users");
users.trigger(
"add", {}, users
);
break;
}
// Debug