Replace muted user set implementation with ES6 Set

This commit is contained in:
Calvin Montgomery 2018-04-08 19:11:54 -07:00
parent 62417f7fb8
commit e9a183bf9a
2 changed files with 8 additions and 41 deletions

View File

@ -32,7 +32,7 @@ const MIN_ANTIFLOOD = {
function ChatModule(_channel) {
ChannelModule.apply(this, arguments);
this.buffer = [];
this.muted = new util.Set();
this.muted = new Set();
this.commandHandlers = {};
this.supportsDirtyCheck = true;
@ -55,7 +55,7 @@ ChatModule.prototype = Object.create(ChannelModule.prototype);
ChatModule.prototype.load = function (data) {
this.buffer = [];
this.muted = new util.Set();
this.muted = new Set();
if ("chatbuffer" in data) {
for (var i = 0; i < data.chatbuffer.length; i++) {
@ -74,7 +74,7 @@ ChatModule.prototype.load = function (data) {
ChatModule.prototype.save = function (data) {
data.chatbuffer = this.buffer;
data.chatmuted = Array.prototype.slice.call(this.muted);
data.chatmuted = Array.from(this.muted);
};
ChatModule.prototype.packInfo = function (data, _isAdmin) {
@ -102,8 +102,8 @@ ChatModule.prototype.onUserPostJoin = function (user) {
};
ChatModule.prototype.isMuted = function (name) {
return this.muted.contains(name.toLowerCase()) ||
this.muted.contains(SHADOW_TAG + name.toLowerCase());
return this.muted.has(name.toLowerCase()) ||
this.muted.has(SHADOW_TAG + name.toLowerCase());
};
ChatModule.prototype.mutedUsers = function () {
@ -114,7 +114,7 @@ ChatModule.prototype.mutedUsers = function () {
};
ChatModule.prototype.isShadowMuted = function (name) {
return this.muted.contains(SHADOW_TAG + name.toLowerCase());
return this.muted.has(SHADOW_TAG + name.toLowerCase());
};
ChatModule.prototype.shadowMutedUsers = function () {
@ -667,8 +667,8 @@ ChatModule.prototype.handleCmdUnmute = function (user, msg, _meta) {
return;
}
this.muted.remove(name);
this.muted.remove(SHADOW_TAG + name);
this.muted.delete(name);
this.muted.delete(SHADOW_TAG + name);
this.channel.logger.log("[mod] " + user.getName() + " unmuted " + name);
this.sendModMessage(user.getName() + " unmuted " + name, muteperm);

View File

@ -3,39 +3,6 @@
const net = require("net");
const crypto = require("crypto");
// TODO: now that the Set type is native, find usages and remove this
var Set = function (items) {
this._items = {};
var self = this;
if (items instanceof Array)
items.forEach(function (it) { self.add(it); });
};
Set.prototype.contains = function (what) {
return (what in this._items);
};
Set.prototype.add = function (what) {
this._items[what] = true;
};
Set.prototype.remove = function (what) {
if (what in this._items)
delete this._items[what];
};
Set.prototype.clear = function () {
this._items = {};
};
Set.prototype.forEach = function (fn) {
for (var k in this._items) {
fn(k);
}
};
root.Set = Set;
root.isValidChannelName = function (name) {
return name.match(/^[\w-]{1,30}$/);
},