Added nick, quit, messages and topic

This commit is contained in:
Mattias Erming 2014-03-29 20:12:29 -07:00
parent e3bfc43a78
commit 4f5f9a67f2
4 changed files with 93 additions and 46 deletions

View File

@ -11,6 +11,9 @@ h2 {
font: inherit; font: inherit;
margin: 0; margin: 0;
} }
.nav > li > a:hover {
background: #f9f9f9;
}
#wrap, #wrap,
#viewport { #viewport {
height: 100%; height: 100%;

View File

@ -99,7 +99,7 @@
{{#each messages}} {{#each messages}}
<div class="message {{type}}"> <div class="message {{type}}">
<span class="time">{{time}}</span> <span class="time">{{time}}</span>
<a href="{{user}}" class="user">{{mode}}{{user}}</a> <a href="{{from}}" class="user">{{mode}}{{from}}</a>
<span class="text">{{type}} {{{link message}}}</span> <span class="text">{{type}} {{{link message}}}</span>
</div> </div>
{{/each}} {{/each}}
@ -124,7 +124,7 @@
{{#messages}} {{#messages}}
<div class="message {{type}}"> <div class="message {{type}}">
<span class="time">{{time}}</span> <span class="time">{{time}}</span>
<a href="{{user}}" class="user">{{mode}}{{user}}</a> <a href="{{from}}" class="user">{{mode}}{{from}}</a>
<span class="text">{{type}} {{{link message}}}</span> <span class="text">{{type}} {{{link message}}}</span>
</div> </div>
{{/messages}} {{/messages}}

View File

@ -138,12 +138,12 @@ models.Networks = Backbone.Collection.extend({
this.add({host: "Status"}); this.add({host: "Status"});
}, },
find: function(id) { find: function(id) {
var networks = this.models; var i = this.models.length;
for (var i = 0; i < networks.length; i++) { while (i--) {
var find = networks[i].get("channels").findWhere({id: id}); var find = this.models[i].get("channels").findWhere({id: id});
if (find) { if (find) {
return { return {
network: networks[i], network: this.models[i],
channel: find channel: find
}; };
} }

View File

@ -9,15 +9,13 @@ var sockets = null;
var networks = new models.Networks; var networks = new models.Networks;
var events = [ var events = [
"away",
"join", "join",
"kick", "kick",
"message",
"names", "names",
"nick", "nick",
"notice", "notice",
"part", "part",
"pong",
"privmsg",
"quit", "quit",
"topic", "topic",
"welcome", "welcome",
@ -76,6 +74,8 @@ function input(json) {
var network = target.network; var network = target.network;
var channel = target.channel; var channel = target.channel;
var client = network.get("client");
var id = json.id; var id = json.id;
var text = json.text; var text = json.text;
@ -90,8 +90,15 @@ function input(json) {
channel.get("name") channel.get("name")
); );
case "msg": case "msg":
var user;
var message = _.tail(args, 2).join(" ");
if (client) {
user = client.me;
client.send(args[1], message);
}
channel.addMessage({ channel.addMessage({
message: _.tail(args, 2).join(" ") from: user,
message: message,
}); });
break; break;
@ -102,21 +109,28 @@ function input(json) {
} }
break; break;
case "join":
case "part":
case "nick":
if (client && args[1]) {
client[cmd](args[1]);
}
break;
case "topic":
if (client && args[1]) {
var str = "TOPIC " + args[1];
if (args[2]) {
str += " :" + args.slice(2).join(" ");
}
client.write(str);
}
break;
case "quit": case "quit":
case "disconnect": case "disconnect":
networks.remove(network); networks.remove(network);
break; networks.trigger("network", networks);
case "join":
if (args[1]) {
network.get("client").join(args[1]);
}
break;
case "part":
if (args[1]) {
network.get("client").part(args[1]);
}
break; break;
} }
@ -127,15 +141,11 @@ function event(event, data) {
switch (event) { switch (event) {
case "away":
console.log(event);
break;
case "join": case "join":
var chan = channels.findWhere({name: data.channel}) || channels.add({name: data.channel}); var chan = channels.findWhere({name: data.channel}) || channels.add({name: data.channel});
chan.addUser({name: data.nick}); chan.addUser({name: data.nick});
chan.addMessage({ chan.addMessage({
user: data.nick, from: data.nick,
type: "join", type: "join",
}); });
break; break;
@ -144,13 +154,36 @@ function event(event, data) {
console.log(event); console.log(event);
break; break;
case "message":
var chan = channels.findWhere({name: data.to}) || channels.add({type: "query", name: data.from});
chan.addMessage({
from: data.from,
message: data.message
});
break;
case "names": case "names":
var chan = channels.findWhere({name: data.channel}); var chan = channels.findWhere({name: data.channel});
chan.get("users").reset(_.map(data.names, function(n) { return {name: n}; })); chan.get("users").reset(_.map(data.names, function(n) { return {name: n}; }));
break; break;
case "nick": case "nick":
console.log(event); channels.each(function(chan) {
var users = chan.get("users");
var user = users.findWhere({name: data.nick});
if (!user) {
return;
}
user.set("name", data["new"]);
users.trigger("change", {}, users);
chan.addMessage({
from: data.nick,
message: data["new"],
type: "nick",
});
});
break; break;
case "notice": case "notice":
@ -158,37 +191,47 @@ function event(event, data) {
break; break;
case "part": case "part":
var len = data.channels.length; var i = data.channels.length;
var name = data.nick; while (i--) {
for (var i = 0; i < len; i++) {
var chan = channels.findWhere({name: data.channels[i]}); var chan = channels.findWhere({name: data.channels[i]});
if (name == this.get("client").me) { if (data.nick == this.get("client").me) {
channels.remove(chan); channels.remove(chan);
return; return;
} }
var users = channel.get("users"); var users = chan.get("users");
users.remove(users.findWhere({name: name})); users.remove(users.findWhere({name: data.nick}));
chan.addMessage({ chan.addMessage({
user: data.nick, from: data.nick,
type: "part", type: "part",
}); });
} }
break; break;
case "pong":
console.log(event);
break;
case "privmsg":
console.log(event);
break;
case "quit": case "quit":
console.log(event); channels.each(function(chan) {
var users = chan.get("users");
var user = users.findWhere({name: data.nick});
if (user) {
users.remove(user);
chan.addMessage({
from: data.nick,
type: "quit",
});
}
});
break; break;
case "topic": case "topic":
console.log(event); var chan = channels.findWhere({name: data.channel});
var from = data.nick;
if (from == this.get("client").me) {
from = data.channel;
}
chan.addMessage({
from: from,
message: data.topic,
type: "topic",
});
break; break;
case "welcome": case "welcome":
@ -196,11 +239,12 @@ function event(event, data) {
break; break;
case "whois": case "whois":
console.log(event); // ..
break; break;
} }
// Debug // Debug
console.log(event + ":");
console.log(data); console.log(data);
} }