mirror of https://github.com/calzoneman/sync.git
Replace muted user set implementation with ES6 Set
This commit is contained in:
parent
62417f7fb8
commit
e9a183bf9a
|
@ -32,7 +32,7 @@ const MIN_ANTIFLOOD = {
|
||||||
function ChatModule(_channel) {
|
function ChatModule(_channel) {
|
||||||
ChannelModule.apply(this, arguments);
|
ChannelModule.apply(this, arguments);
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.muted = new util.Set();
|
this.muted = new Set();
|
||||||
this.commandHandlers = {};
|
this.commandHandlers = {};
|
||||||
this.supportsDirtyCheck = true;
|
this.supportsDirtyCheck = true;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ ChatModule.prototype = Object.create(ChannelModule.prototype);
|
||||||
|
|
||||||
ChatModule.prototype.load = function (data) {
|
ChatModule.prototype.load = function (data) {
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.muted = new util.Set();
|
this.muted = new Set();
|
||||||
|
|
||||||
if ("chatbuffer" in data) {
|
if ("chatbuffer" in data) {
|
||||||
for (var i = 0; i < data.chatbuffer.length; i++) {
|
for (var i = 0; i < data.chatbuffer.length; i++) {
|
||||||
|
@ -74,7 +74,7 @@ ChatModule.prototype.load = function (data) {
|
||||||
|
|
||||||
ChatModule.prototype.save = function (data) {
|
ChatModule.prototype.save = function (data) {
|
||||||
data.chatbuffer = this.buffer;
|
data.chatbuffer = this.buffer;
|
||||||
data.chatmuted = Array.prototype.slice.call(this.muted);
|
data.chatmuted = Array.from(this.muted);
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatModule.prototype.packInfo = function (data, _isAdmin) {
|
ChatModule.prototype.packInfo = function (data, _isAdmin) {
|
||||||
|
@ -102,8 +102,8 @@ ChatModule.prototype.onUserPostJoin = function (user) {
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatModule.prototype.isMuted = function (name) {
|
ChatModule.prototype.isMuted = function (name) {
|
||||||
return this.muted.contains(name.toLowerCase()) ||
|
return this.muted.has(name.toLowerCase()) ||
|
||||||
this.muted.contains(SHADOW_TAG + name.toLowerCase());
|
this.muted.has(SHADOW_TAG + name.toLowerCase());
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatModule.prototype.mutedUsers = function () {
|
ChatModule.prototype.mutedUsers = function () {
|
||||||
|
@ -114,7 +114,7 @@ ChatModule.prototype.mutedUsers = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatModule.prototype.isShadowMuted = function (name) {
|
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 () {
|
ChatModule.prototype.shadowMutedUsers = function () {
|
||||||
|
@ -667,8 +667,8 @@ ChatModule.prototype.handleCmdUnmute = function (user, msg, _meta) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.muted.remove(name);
|
this.muted.delete(name);
|
||||||
this.muted.remove(SHADOW_TAG + name);
|
this.muted.delete(SHADOW_TAG + name);
|
||||||
|
|
||||||
this.channel.logger.log("[mod] " + user.getName() + " unmuted " + name);
|
this.channel.logger.log("[mod] " + user.getName() + " unmuted " + name);
|
||||||
this.sendModMessage(user.getName() + " unmuted " + name, muteperm);
|
this.sendModMessage(user.getName() + " unmuted " + name, muteperm);
|
||||||
|
|
|
@ -3,39 +3,6 @@
|
||||||
const net = require("net");
|
const net = require("net");
|
||||||
const crypto = require("crypto");
|
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) {
|
root.isValidChannelName = function (name) {
|
||||||
return name.match(/^[\w-]{1,30}$/);
|
return name.match(/^[\w-]{1,30}$/);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue