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;
margin: 0;
}
.nav > li > a:hover {
background: #f9f9f9;
}
#wrap,
#viewport {
height: 100%;

View File

@ -99,7 +99,7 @@
{{#each messages}}
<div class="message {{type}}">
<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>
</div>
{{/each}}
@ -124,7 +124,7 @@
{{#messages}}
<div class="message {{type}}">
<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>
</div>
{{/messages}}

View File

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

View File

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