Merge pull request #417 from thelounge/xpaw/channels
Store channels in array format
This commit is contained in:
commit
2ffcbd8533
@ -141,13 +141,34 @@ Client.prototype.connect = function(args) {
|
|||||||
var webirc = null;
|
var webirc = null;
|
||||||
var channels = [];
|
var channels = [];
|
||||||
|
|
||||||
if (args.join) {
|
if (args.channels) {
|
||||||
var join = args.join.replace(/\,/g, " ").split(/\s+/g);
|
var badName = false;
|
||||||
join.forEach(function(chan) {
|
|
||||||
|
args.channels.forEach(function(chan) {
|
||||||
|
if (!chan.name) {
|
||||||
|
badName = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
channels.push(new Chan({
|
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({
|
var network = new Network({
|
||||||
|
@ -73,10 +73,15 @@ Network.prototype.export = function() {
|
|||||||
"hostname"
|
"hostname"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
network.join = _.map(
|
network.channels = this.channels
|
||||||
_.filter(this.channels, {type: Chan.Type.CHANNEL}),
|
.filter(function(channel) {
|
||||||
|
return channel.type === Chan.Type.CHANNEL;
|
||||||
|
})
|
||||||
|
.map(function(chan) {
|
||||||
|
return _.pick(chan, [
|
||||||
"name"
|
"name"
|
||||||
).join(",");
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
return network;
|
return network;
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,8 @@ describe("Network", function() {
|
|||||||
network.setNick("chillin`");
|
network.setNick("chillin`");
|
||||||
network.channels.push(new Chan({name: "#thelounge"}));
|
network.channels.push(new Chan({name: "#thelounge"}));
|
||||||
network.channels.push(new Chan({name: "&foobar"}));
|
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({
|
expect(network.export()).to.deep.equal({
|
||||||
name: "networkName",
|
name: "networkName",
|
||||||
@ -24,9 +26,12 @@ describe("Network", function() {
|
|||||||
realname: "",
|
realname: "",
|
||||||
commands: [],
|
commands: [],
|
||||||
nick: "chillin`",
|
nick: "chillin`",
|
||||||
join: "#thelounge,&foobar",
|
|
||||||
ip: null,
|
ip: null,
|
||||||
hostname: null
|
hostname: null,
|
||||||
|
channels: [
|
||||||
|
{"name": "#thelounge"},
|
||||||
|
{"name": "&foobar"},
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user