2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-10 20:44:14 +00:00
|
|
|
const Chan = require("../../models/chan");
|
2016-03-09 20:04:07 +00:00
|
|
|
|
|
|
|
module.exports = function(irc, network) {
|
2017-11-10 20:44:14 +00:00
|
|
|
const client = this;
|
|
|
|
const MAX_CHANS = 500;
|
2016-03-09 20:04:07 +00:00
|
|
|
|
|
|
|
irc.on("channel list start", function() {
|
2016-05-29 02:07:34 +00:00
|
|
|
network.chanCache = [];
|
2016-03-09 20:04:07 +00:00
|
|
|
|
2018-07-10 09:37:48 +00:00
|
|
|
updateListStatus({
|
2016-03-09 20:04:07 +00:00
|
|
|
text: "Loading channel list, this can take a moment...",
|
2018-07-10 09:37:48 +00:00
|
|
|
});
|
2016-03-09 20:04:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("channel list", function(channels) {
|
2016-05-29 02:07:34 +00:00
|
|
|
Array.prototype.push.apply(network.chanCache, channels);
|
2018-07-10 09:37:48 +00:00
|
|
|
|
|
|
|
updateListStatus({
|
|
|
|
text: `Loaded ${network.chanCache.length} channels...`,
|
|
|
|
});
|
2016-03-09 20:04:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("channel list end", function() {
|
2018-07-10 09:37:48 +00:00
|
|
|
updateListStatus(network.chanCache.sort((a, b) => b.num_users - a.num_users).slice(0, MAX_CHANS));
|
2016-03-09 20:04:07 +00:00
|
|
|
|
2016-05-29 02:07:34 +00:00
|
|
|
network.chanCache = [];
|
2016-03-09 20:04:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function updateListStatus(msg) {
|
2017-11-10 20:44:14 +00:00
|
|
|
let chan = network.getChannel("Channel List");
|
|
|
|
|
2016-03-09 20:04:07 +00:00
|
|
|
if (typeof chan === "undefined") {
|
2018-04-27 10:16:23 +00:00
|
|
|
chan = client.createChannel({
|
2016-03-09 20:04:07 +00:00
|
|
|
type: Chan.Type.SPECIAL,
|
2018-07-10 09:37:48 +00:00
|
|
|
special: Chan.SpecialType.CHANNELLIST,
|
2017-11-15 06:35:15 +00:00
|
|
|
name: "Channel List",
|
2018-07-10 09:37:48 +00:00
|
|
|
data: msg,
|
2016-03-09 20:04:07 +00:00
|
|
|
});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
2016-03-09 20:04:07 +00:00
|
|
|
client.emit("join", {
|
2018-04-26 09:06:01 +00:00
|
|
|
network: network.uuid,
|
2017-12-03 14:29:50 +00:00
|
|
|
chan: chan.getFilteredClone(true),
|
2018-03-12 12:42:59 +00:00
|
|
|
index: network.addChannel(chan),
|
2016-03-09 20:04:07 +00:00
|
|
|
});
|
2018-07-10 09:37:48 +00:00
|
|
|
} else {
|
|
|
|
chan.data = msg;
|
2016-03-09 20:04:07 +00:00
|
|
|
|
2018-07-10 09:37:48 +00:00
|
|
|
client.emit("msg:special", {
|
|
|
|
chan: chan.id,
|
|
|
|
data: msg,
|
|
|
|
});
|
|
|
|
}
|
2016-03-09 20:04:07 +00:00
|
|
|
}
|
|
|
|
};
|