Added network export function

This commit is contained in:
Mattias Erming 2014-10-11 22:44:56 +02:00
parent 1b476bfefd
commit 81401cec0f
2 changed files with 34 additions and 5 deletions

View File

@ -120,9 +120,9 @@ Client.prototype.connect = function(args) {
var config = Helper.getConfig();
var client = this;
var server = {
name: args.name || "",
host: args.host || "irc.freenode.org",
port: args.port || (args.tls ? 6697 : 6667),
name: args.name || "",
rejectUnauthorized: false
};
@ -164,11 +164,17 @@ Client.prototype.connect = function(args) {
irc.user(username, realname);
var network = new Network({
host: server.host,
name: server.name,
irc: irc
host: server.host,
port: server.port,
tls: args.tls,
password: args.password,
username: username,
realname: realname,
});
network.irc = irc;
client.networks.push(network);
client.emit("network", {
network: network
@ -312,3 +318,7 @@ Client.prototype.quit = function() {
}
});
};
Client.prototype.save = function() {
var networks = _.map(this.networks, function(n) { return n.export(); });
};

View File

@ -7,9 +7,15 @@ var id = 0;
function Network(attr) {
_.merge(this, _.extend({
name: "",
host: "",
port: 6667,
tls: false,
password: "",
username: "",
realname: "",
channels: [],
connected: false,
host: "",
id: id++,
irc: null,
}, attr));
@ -21,7 +27,20 @@ function Network(attr) {
Network.prototype.toJSON = function() {
var json = _.extend(this, {nick: (this.irc || {}).me || ""});
return _.omit(json, "irc");
return _.omit(json, "irc", "password");
};
Network.prototype.export = function() {
var network = _.pick(
this,
["name", "host", "port", "tls", "password", "username", "realname"]
);
network.nick = (this.irc || {}).me;
network.join = _.pluck(
_.where(this.channels, {type: "channel"}),
"name"
);
return network;
};
function prettify(host) {