thelounge/src/plugins/irc-events/list.js
Jérémie Astori caa46042bf Enforce strict mode across all JS files with ESLint
Several ES6 additions are only available in strict mode. Example:
> SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Strict mode was also enabled in a few of our files already, and it is a good thing to have anyway.
2016-10-09 15:14:02 -04:00

59 lines
1.2 KiB
JavaScript

"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
var MAX_CHANS = 1000;
irc.on("channel list start", function() {
network.chanCache = [];
updateListStatus(new Msg({
text: "Loading channel list, this can take a moment...",
type: "channel_list_loading"
}));
});
irc.on("channel list", function(channels) {
Array.prototype.push.apply(network.chanCache, channels);
});
irc.on("channel list end", function() {
updateListStatus(new Msg({
type: "channel_list",
channels: network.chanCache.slice(0, MAX_CHANS)
}));
if (network.chanCache.length > MAX_CHANS) {
updateListStatus(new Msg({
type: "channel_list_truncated",
text: "Channel list is too large: truncated to " + MAX_CHANS + " channels."
}));
}
network.chanCache = [];
});
function updateListStatus(msg) {
var chan = network.getChannel("Channel List");
if (typeof chan === "undefined") {
chan = new Chan({
type: Chan.Type.SPECIAL,
name: "Channel List"
});
network.channels.push(chan);
client.emit("join", {
network: network.id,
chan: chan
});
}
client.emit("msg", {
chan: chan.id,
msg: msg
});
}
};