2022-06-18 20:25:21 -04:00
|
|
|
import {IrcEventHandler} from "../../client";
|
2016-10-09 15:14:02 -04:00
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
import Chan, {ChanType, SpecialChanType} from "../../models/chan";
|
2016-03-09 15:04:07 -05:00
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
export default <IrcEventHandler>function (irc, network) {
|
2017-11-10 15:44:14 -05:00
|
|
|
const client = this;
|
|
|
|
const MAX_CHANS = 500;
|
2016-03-09 15:04:07 -05:00
|
|
|
|
2020-03-21 16:55:36 -04:00
|
|
|
irc.on("channel list start", function () {
|
2016-05-28 22:07:34 -04:00
|
|
|
network.chanCache = [];
|
2016-03-09 15:04:07 -05:00
|
|
|
|
2018-07-10 05:37:48 -04:00
|
|
|
updateListStatus({
|
2016-03-09 15:04:07 -05:00
|
|
|
text: "Loading channel list, this can take a moment...",
|
2018-07-10 05:37:48 -04:00
|
|
|
});
|
2016-03-09 15:04:07 -05:00
|
|
|
});
|
|
|
|
|
2020-03-21 16:55:36 -04:00
|
|
|
irc.on("channel list", function (channels) {
|
2016-05-28 22:07:34 -04:00
|
|
|
Array.prototype.push.apply(network.chanCache, channels);
|
2018-07-10 05:37:48 -04:00
|
|
|
|
|
|
|
updateListStatus({
|
|
|
|
text: `Loaded ${network.chanCache.length} channels...`,
|
|
|
|
});
|
2016-03-09 15:04:07 -05:00
|
|
|
});
|
|
|
|
|
2020-03-21 16:55:36 -04:00
|
|
|
irc.on("channel list end", function () {
|
2019-07-17 05:33:59 -04:00
|
|
|
updateListStatus(
|
2022-06-18 20:25:21 -04:00
|
|
|
network.chanCache.sort((a, b) => b.num_users! - a.num_users!).slice(0, MAX_CHANS)
|
2019-07-17 05:33:59 -04:00
|
|
|
);
|
2016-03-09 15:04:07 -05:00
|
|
|
|
2016-05-28 22:07:34 -04:00
|
|
|
network.chanCache = [];
|
2016-03-09 15:04:07 -05:00
|
|
|
});
|
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
function updateListStatus(
|
|
|
|
msg:
|
|
|
|
| {
|
|
|
|
text: string;
|
|
|
|
}
|
|
|
|
| Chan[]
|
|
|
|
) {
|
2017-11-10 15:44:14 -05:00
|
|
|
let chan = network.getChannel("Channel List");
|
|
|
|
|
2016-03-09 15:04:07 -05:00
|
|
|
if (typeof chan === "undefined") {
|
2018-04-27 06:16:23 -04:00
|
|
|
chan = client.createChannel({
|
2022-06-18 20:25:21 -04:00
|
|
|
type: ChanType.SPECIAL,
|
|
|
|
special: SpecialChanType.CHANNELLIST,
|
2017-11-15 01:35:15 -05:00
|
|
|
name: "Channel List",
|
2018-07-10 05:37:48 -04:00
|
|
|
data: msg,
|
2016-03-09 15:04:07 -05:00
|
|
|
});
|
2018-03-12 08:42:59 -04:00
|
|
|
|
2016-03-09 15:04:07 -05:00
|
|
|
client.emit("join", {
|
2018-04-26 05:06:01 -04:00
|
|
|
network: network.uuid,
|
2017-12-03 09:29:50 -05:00
|
|
|
chan: chan.getFilteredClone(true),
|
2018-03-12 08:42:59 -04:00
|
|
|
index: network.addChannel(chan),
|
2016-03-09 15:04:07 -05:00
|
|
|
});
|
2018-07-10 05:37:48 -04:00
|
|
|
} else {
|
|
|
|
chan.data = msg;
|
2016-03-09 15:04:07 -05:00
|
|
|
|
2018-07-10 05:37:48 -04:00
|
|
|
client.emit("msg:special", {
|
|
|
|
chan: chan.id,
|
|
|
|
data: msg,
|
|
|
|
});
|
|
|
|
}
|
2016-03-09 15:04:07 -05:00
|
|
|
}
|
|
|
|
};
|