From 08f9e01b7a8311feb1054c3978526ec66d04e5e5 Mon Sep 17 00:00:00 2001 From: Andrei Husanu Date: Fri, 12 Jun 2015 19:50:43 +0300 Subject: [PATCH] better way of finding what channels a user is in Generate the correct list of channels where the user is in (for commands: QUIT, NICK and KILL) --- lib/irc.js | 24 +++++++++++++++--------- package.json | 3 ++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/irc.js b/lib/irc.js index b9159b25..e2531d7c 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -313,12 +313,14 @@ function Client(server, nick, opt) { channels = []; - // TODO better way of finding what channels a user is in? + // finding what channels a user is in Object.keys(self.chans).forEach(function(channame) { var channel = self.chans[channame]; - channel.users[message.args[0]] = channel.users[message.nick]; - delete channel.users[message.nick]; - channels.push(channame); + if (message.nick in channel.users) { + channel.users[message.args[0]] = channel.users[message.nick]; + delete channel.users[message.nick]; + channels.push(channame); + } }); // old nick, new nick, channels @@ -501,8 +503,10 @@ function Client(server, nick, opt) { channels = []; Object.keys(self.chans).forEach(function(channame) { var channel = self.chans[channame]; - channels.push(channame); - delete channel.users[nick]; + if (nick in channel.users) { + channels.push(channame); + delete channel.users[nick]; + } }); self.emit('kill', nick, message.args[1], channels, message); break; @@ -544,11 +548,13 @@ function Client(server, nick, opt) { channels = []; - // TODO better way of finding what channels a user is in? + // finding what channels a user is in? Object.keys(self.chans).forEach(function(channame) { var channel = self.chans[channame]; - delete channel.users[message.nick]; - channels.push(channame); + if (message.nick in channel.users) { + delete channel.users[message.nick]; + channels.push(channame); + } }); // who, reason, channels diff --git a/package.json b/package.json index 62c4d414..53de93cf 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "Justin Gallardo ", "Chris Nehren ", "Henri Niemeläinen ", - "Alex Miles " + "Alex Miles ", + "Andrei Husanu " ], "repository": { "type": "git",