Switch to maps for action deleted + more cleaning (#592)

This commit is contained in:
Schuyler Cebulskie
2016-09-03 18:21:31 -04:00
committed by Amish Shah
parent a3b9b0f1b4
commit 5af09d335c
7 changed files with 23 additions and 36 deletions

View File

@@ -4,8 +4,7 @@ class ChannelDeleteAction extends Action {
constructor(client) {
super(client);
this.timeouts = [];
this.deleted = {};
this.deleted = new Map();
}
handle(data) {
@@ -14,10 +13,10 @@ class ChannelDeleteAction extends Action {
let channel = client.channels.get(data.id);
if (channel) {
client.dataManager.killChannel(channel);
this.deleted[channel.id] = channel;
this.deleted.set(channel.id, channel);
this.scheduleForDeletion(channel.id);
} else if (this.deleted[data.id]) {
channel = this.deleted[data.id];
} else {
channel = this.deleted.get(data.id) || null;
}
return {
@@ -26,7 +25,7 @@ class ChannelDeleteAction extends Action {
}
scheduleForDeletion(id) {
this.client.setTimeout(() => delete this.deleted[id], this.client.options.rest_ws_bridge_timeout);
this.client.setTimeout(() => this.deleted.delete(id), this.client.options.rest_ws_bridge_timeout);
}
}

View File

@@ -5,7 +5,7 @@ class GuildDeleteAction extends Action {
constructor(client) {
super(client);
this.deleted = {};
this.deleted = new Map();
}
handle(data) {
@@ -27,10 +27,10 @@ class GuildDeleteAction extends Action {
// delete guild
client.guilds.delete(guild.id);
this.deleted[guild.id] = guild;
this.deleted.set(guild.id, guild);
this.scheduleForDeletion(guild.id);
} else if (this.deleted[data.id]) {
guild = this.deleted[data.id];
} else {
guild = this.deleted.get(data.id) || null;
}
return {
@@ -39,7 +39,7 @@ class GuildDeleteAction extends Action {
}
scheduleForDeletion(id) {
this.client.setTimeout(() => delete this.deleted[id], this.client.options.rest_ws_bridge_timeout);
this.client.setTimeout(() => this.deleted.delete(id), this.client.options.rest_ws_bridge_timeout);
}
}

View File

@@ -5,7 +5,7 @@ class GuildMemberRemoveAction extends Action {
constructor(client) {
super(client);
this.deleted = {};
this.deleted = new Map();
}
handle(data) {
@@ -17,11 +17,11 @@ class GuildMemberRemoveAction extends Action {
if (member) {
guild.memberCount--;
guild._removeMember(member);
this.deleted[guild.id + data.user.id] = member;
this.deleted.set(guild.id + data.user.id, member);
if (client.status === Constants.Status.READY) client.emit(Constants.Events.GUILD_MEMBER_REMOVE, guild, member);
this.scheduleForDeletion(guild.id, data.user.id);
} else {
member = this.deleted[guild.id + data.user.id];
member = this.deleted.get(guild.id + data.user.id) || null;
}
return {
@@ -37,7 +37,7 @@ class GuildMemberRemoveAction extends Action {
}
scheduleForDeletion(guildID, userID) {
this.client.setTimeout(() => delete this.deleted[guildID + userID], this.client.options.rest_ws_bridge_timeout);
this.client.setTimeout(() => this.deleted.delete(guildID + userID), this.client.options.rest_ws_bridge_timeout);
}
}

View File

@@ -5,7 +5,7 @@ class GuildRoleDeleteAction extends Action {
constructor(client) {
super(client);
this.deleted = {};
this.deleted = new Map();
}
handle(data) {
@@ -16,11 +16,11 @@ class GuildRoleDeleteAction extends Action {
let role = guild.roles.get(data.role_id);
if (role) {
guild.roles.delete(data.role_id);
this.deleted[guild.id + data.role_id] = role;
this.deleted.set(guild.id + data.role_id, role);
this.scheduleForDeletion(guild.id, data.role_id);
client.emit(Constants.Events.GUILD_ROLE_DELETE, guild, role);
} else {
role = this.deleted[guild.id + data.role_id];
role = this.deleted.get(guild.id + data.role_id) || null;
}
return {
@@ -34,7 +34,7 @@ class GuildRoleDeleteAction extends Action {
}
scheduleForDeletion(guildID, roleID) {
this.client.setTimeout(() => delete this.deleted[guildID + roleID], this.client.options.rest_ws_bridge_timeout);
this.client.setTimeout(() => this.deleted.delete(guildID + roleID), this.client.options.rest_ws_bridge_timeout);
}
}

View File

@@ -4,12 +4,6 @@ const cloneObject = require('../../util/CloneObject');
class GuildUpdateAction extends Action {
constructor(client) {
super(client);
this.deleted = {};
this.timeouts = [];
}
handle(data) {
const client = this.client;

View File

@@ -4,7 +4,7 @@ class MessageDeleteAction extends Action {
constructor(client) {
super(client);
this.deleted = {};
this.deleted = new Map();
}
handle(data) {
@@ -16,10 +16,10 @@ class MessageDeleteAction extends Action {
if (message) {
channel.messages.delete(message.id);
this.deleted[channel.id + message.id] = message;
this.deleted.set(channel.id + message.id, message);
this.scheduleForDeletion(channel.id, message.id);
} else if (this.deleted[channel.id + data.id]) {
message = this.deleted[channel.id + data.id];
} else {
message = this.deleted.get(channel.id + data.id) || null;
}
return {
@@ -33,7 +33,7 @@ class MessageDeleteAction extends Action {
}
scheduleForDeletion(channelID, messageID) {
this.client.setTimeout(() => delete this.deleted[channelID + messageID],
this.client.setTimeout(() => this.deleted.delete(channelID + messageID),
this.client.options.rest_ws_bridge_timeout);
}
}

View File

@@ -4,12 +4,6 @@ const Constants = require('../../util/Constants');
class MessageDeleteBulkAction extends Action {
constructor(client) {
super(client);
this.timeouts = [];
this.deleted = {};
}
handle(data) {
const client = this.client;
const channel = client.channels.get(data.channel_id);