Merge pull request #417 from thelounge/xpaw/channels

Store channels in array format
This commit is contained in:
Jérémie Astori 2016-07-03 17:56:08 -04:00 committed by GitHub
commit 2ffcbd8533
3 changed files with 41 additions and 10 deletions

View File

@ -141,13 +141,34 @@ Client.prototype.connect = function(args) {
var webirc = null;
var channels = [];
if (args.join) {
var join = args.join.replace(/\,/g, " ").split(/\s+/g);
join.forEach(function(chan) {
if (args.channels) {
var badName = false;
args.channels.forEach(function(chan) {
if (!chan.name) {
badName = true;
return;
}
channels.push(new Chan({
name: chan
name: chan.name
}));
});
if (badName && client.name) {
log.warn("User '" + client.name + "' on network '" + args.name + "' has an invalid channel which has been ignored");
}
// `join` is kept for backwards compatibility when updating from versions <2.0
// also used by the "connect" window
} else if (args.join) {
channels = args.join
.replace(/\,/g, " ")
.split(/\s+/g)
.map(function(chan) {
return new Chan({
name: chan
});
});
}
var network = new Network({

View File

@ -73,10 +73,15 @@ Network.prototype.export = function() {
"hostname"
]);
network.join = _.map(
_.filter(this.channels, {type: Chan.Type.CHANNEL}),
"name"
).join(",");
network.channels = this.channels
.filter(function(channel) {
return channel.type === Chan.Type.CHANNEL;
})
.map(function(chan) {
return _.pick(chan, [
"name"
]);
});
return network;
};

View File

@ -13,6 +13,8 @@ describe("Network", function() {
network.setNick("chillin`");
network.channels.push(new Chan({name: "#thelounge"}));
network.channels.push(new Chan({name: "&foobar"}));
network.channels.push(new Chan({name: "Lobby", type: Chan.Type.LOBBY}));
network.channels.push(new Chan({name: "PrivateChat", type: Chan.Type.QUERY}));
expect(network.export()).to.deep.equal({
name: "networkName",
@ -24,9 +26,12 @@ describe("Network", function() {
realname: "",
commands: [],
nick: "chillin`",
join: "#thelounge,&foobar",
ip: null,
hostname: null
hostname: null,
channels: [
{"name": "#thelounge"},
{"name": "&foobar"},
]
});
});
});