️ Make BanchoChannel#channelMembers a Map instead of plain object

parent e0cd3f9f
......@@ -276,7 +276,7 @@ declare module "bancho.js" {
name: string
topic: string
/** Members of the channel, referenced by their name */
channelMembers: BanchoChannelMember[]
channelMembers: Map<string, BanchoChannelMember>
/**
* Sends a message to this channel
*/
......
......@@ -7,7 +7,7 @@ const OutgoingBanchoMessage = require("./OutgoingBanchoMessage.js");
* @prop {string} name Channel name as it is referred to on IRC (including #)
* @prop {string} topic
* @prop {boolean} joined Whether we've joined the channel or not
* @prop {BanchoChannelMember[]} channelMembers Members of the channel, referenced by their name
* @prop {Map<string,BanchoChannelMember>} channelMembers Members of the channel, referenced by their name
* @extends EventEmitter
*/
class BanchoChannel extends EventEmitter {
......@@ -26,7 +26,7 @@ class BanchoChannel extends EventEmitter {
this.joinPromise = null;
this.partCallback = null;
this.partPromise = null;
this.channelMembers = {};
this.channelMembers = new Map();
this.listenersInitialized = false;
}
......
......@@ -26,8 +26,9 @@ class JoinCommand extends IrcCommand {
* @event BanchoClient#JOIN
* @type {BanchoChannelMember}
*/
channel.channelMembers[user.ircUsername] = new BanchoChannelMember(client, channel, user.ircUsername);
client.emit("JOIN", channel.channelMembers[user.ircUsername]);
const member = new BanchoChannelMember(client, channel, user.ircUsername);
channel.channelMembers.set(user.ircUsername, member);
client.emit("JOIN", member);
if(user.isClient()) {
channel.joined = true;
if(channel.joinCallback != null)
......
......@@ -15,7 +15,7 @@ class ModeCommand extends IrcCommand {
const channel = client.getChannel(splits[2]);
const user = client.getUser(splits[4]);
channel.channelMembers[user.ircUsername].mode = modes[splits[3].substr(1, 1)];
channel.channelMembers.get(user.ircUsername).mode = modes[splits[3].substr(1, 1)];
}
}
......
......@@ -21,7 +21,13 @@ class NamesCommand extends IrcCommand {
for(const username of splits) {
const channelMember = new BanchoChannelMember(client, channel, username);
channel.channelMembers[channelMember.user.ircUsername] = channelMember;
const currentMember = channel.channelMembers.get(username);
if(currentMember) {
if(currentMember.mode !== channelMember.mode)
currentMember.mode = channelMember.mode;
} else {
channel.channelMembers.set(channelMember.user.ircUsername, channelMember);
}
}
}
}
......
......@@ -25,15 +25,14 @@ class PartCommand extends JoinCommand {
* @event BanchoClient#PART
* @type {BanchoChannelMember}
*/
client.emit("PART", channel.channelMembers[user.ircUsername]);
client.emit("PART", channel.channelMembers.get(user.ircUsername));
if(user.isClient()) {
channel.joined = false;
channel.channelMembers = {};
channel.channelMembers = new Map();
if(channel.partCallback != null)
channel.partCallback();
}
if(channel.channelMembers[user.ircUsername] != null)
delete channel.channelMembers[user.ircUsername];
channel.channelMembers.delete(user.ircUsername);
}
}
......
......@@ -20,8 +20,7 @@ class QuitCommand extends IrcCommand {
*/
client.emit("QUIT", user);
for(const channel of client.channels.values())
if(channel.channelMembers[user.ircUsername] != null)
delete channel.channelMembers[user.ircUsername];
channel.channelMembers.delete(user.ircUsername);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment