thelounge/src/models/network.js

39 lines
712 B
JavaScript
Raw Normal View History

2014-06-27 01:05:47 +02:00
var _ = require("lodash");
2014-06-29 21:41:02 +02:00
var Chan = require("./chan");
2014-06-27 01:05:47 +02:00
module.exports = Network;
2014-06-29 03:07:38 +02:00
var id = 0;
2014-06-27 01:05:47 +02:00
function Network(attr) {
_.merge(this, _.extend({
2014-07-08 22:50:41 +02:00
channels: [],
2014-06-27 01:05:47 +02:00
connected: false,
host: "",
2014-07-08 22:50:41 +02:00
id: id++,
2014-09-10 00:32:19 +02:00
irc: null,
2014-06-27 01:05:47 +02:00
}, attr));
2014-09-10 00:32:19 +02:00
this.name = attr.name || prettify(attr.host);
2014-06-29 21:41:02 +02:00
this.channels.unshift(
new Chan({name: this.name, type: Chan.Type.LOBBY})
);
2014-06-27 01:05:47 +02:00
}
2014-06-29 21:41:02 +02:00
Network.prototype.toJSON = function() {
return _.omit(this, "irc");
};
2014-07-08 22:50:41 +02:00
function prettify(host) {
var name = capitalize(host.split(".")[1]);
if (!name) {
name = host;
}
return name;
}
2014-06-27 01:05:47 +02:00
function capitalize(str) {
2014-08-25 12:14:28 +02:00
if (typeof str === "string") {
return str.charAt(0).toUpperCase() + str.slice(1);
}
2014-06-27 01:05:47 +02:00
}