Skip to content

Commit

Permalink
better way of finding what channels a user is in
Browse files Browse the repository at this point in the history
Generate the correct list of channels where the user is in (for
commands: QUIT, NICK and KILL)
  • Loading branch information
Andrei Husanu committed Jun 12, 2015
1 parent f7bfd7d commit 08f9e01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 15 additions & 9 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"Justin Gallardo <[email protected]>",
"Chris Nehren <[email protected]>",
"Henri Niemeläinen <[email protected]>",
"Alex Miles <[email protected]>"
"Alex Miles <[email protected]>",
"Andrei Husanu <[email protected]>"
],
"repository": {
"type": "git",
Expand Down

0 comments on commit 08f9e01

Please sign in to comment.