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

View File

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

View File

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

View File

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

View File

@ -84,6 +84,13 @@ function handleInput(input) {
} }
break; break;
case "NAMES":
var irc = target.network.irc;
if (argv[1] && typeof irc !== "undefined") {
irc.send("NAMES", argv[1]);
}
break;
case "SERVER": case "SERVER":
case "CONNECT": case "CONNECT":
if (argv[1]) { if (argv[1]) {
@ -130,16 +137,10 @@ function handleEvent(argv) {
case "JOIN": case "JOIN":
if (argv.nick == network.get("nick")) { 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( channels.add(
channel new models.Channel({
name: argv.args[0]
})
); );
} else { } else {
var channel = channels.findWhere({name: argv.args[0]}); var channel = channels.findWhere({name: argv.args[0]});
@ -179,6 +180,31 @@ function handleEvent(argv) {
); );
} }
break; 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 // Debug