This commit is contained in:
Mattias Erming 2014-04-25 01:57:51 +02:00
parent bea3136078
commit cdad2f64d9
2 changed files with 40 additions and 37 deletions

View file

@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="<%= typeof theme !== 'undefined' ? theme : "" %>">
<link rel="stylesheet" href="<%= typeof theme !== 'undefined' ? theme : '' %>">
</head>
<body>

View file

@ -45,9 +45,7 @@ function listen() {
var self = this;
sockets = io.listen(app, {log: 0}).sockets.on("connection", function(s) {
s.on("input", input);
s.emit("networks", {
networks: networks
});
s.emit("networks", {networks: networks});
});
(config.networks || []).forEach(function(n) {
@ -56,30 +54,27 @@ function listen() {
}
function index(req, res, next) {
if (req.url == "/" || req.url == "/index.html") {
var data = _.extend(
if (req.url != "/") return next();
fs.readFile("client/index.html", function(err, file) {
var data = _.merge(
require("../package.json"),
config
);
fs.readFile(
"client/index.html",
function(e, file) {
res.end(_.template(file, data));
}
);
} else {
next();
}
res.end(_.template(
file,
data
));
});
}
function connect(params) {
params = _.extend(
config.defaults || {},
params
_.defaults(
params,
config.defaults
);
var host = params.host;
var port = params.port;
var port = params.port || 6667;
var stream = net.connect({
port: port,
@ -97,9 +92,7 @@ function connect(params) {
});
networks.push(network);
sockets.emit("networks", {
networks: networks
});
sockets.emit("networks", {networks: networks});
client.nick(params.nick);
client.user(params.nick, params.realname);
@ -243,11 +236,9 @@ function input(data) {
case "quit":
case "disconnect":
if (client) {
client.quit();
networks = _.without(networks, network);
sockets.emit("networks", {
networks: networks
});
sockets.emit("networks", {networks: networks});
client.quit();
}
break;
}
@ -289,6 +280,10 @@ function event(e, data) {
case "kick":
var chan = _.findWhere(channels, {name: data.channel});
if (typeof chan === "undefined") {
// TODO: Throw error
break;
}
if (data.client == this.client.me) {
chan.users = [];
} else {
@ -375,6 +370,10 @@ function event(e, data) {
case "names":
var chan = _.findWhere(channels, {name: data.channel});
if (typeof chan === "undefined") {
// TODO: Throw error
break;
}
chan.users = [];
data.names.forEach(function(n) {
chan.users.push(new User({name: n}));
@ -437,6 +436,10 @@ function event(e, data) {
case "part":
var chan = _.findWhere(channels, {name: data.channels[0]});
if (typeof chan === "undefined") {
// TODO: Throw error
break;
}
if (data.nick == this.client.me) {
remove(chan.id);
sockets.emit("part", {
@ -485,6 +488,10 @@ function event(e, data) {
case "topic":
var chan = _.findWhere(channels, {name: data.channel});
if (typeof chan === "undefined") {
// TODO: Throw error
break;
}
var from = data.nick || chan.name;
var msg = new Msg({
type: "topic",
@ -546,20 +553,16 @@ function event(e, data) {
}
}
// Utils
function find(id) {
var result = false;
networks.forEach(function(n) {
result = {
network: n,
chan: _.findWhere(n.channels, {id: id}),
for (var i = 0; i < networks.length; i++) {
var result = {
network: networks[i],
chan: _.findWhere(networks[i].channels, {id: id}),
};
if (!result.chan) {
result = false;
if (result.chan) {
return result;
}
});
return result;
}
}
function remove(id) {