From e9a183bf9af6963440031ec5a2c0727c4a8107bd Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 8 Apr 2018 19:11:54 -0700 Subject: [PATCH] Replace muted user set implementation with ES6 Set --- src/channel/chat.js | 16 ++++++++-------- src/utilities.js | 33 --------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/src/channel/chat.js b/src/channel/chat.js index 15145c28..a4adc670 100644 --- a/src/channel/chat.js +++ b/src/channel/chat.js @@ -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); diff --git a/src/utilities.js b/src/utilities.js index 59f0e348..2c918eca 100644 --- a/src/utilities.js +++ b/src/utilities.js @@ -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}$/); },