Skip to content

Commit

Permalink
Store NAMES replies in separate Map while processing, override channe…
Browse files Browse the repository at this point in the history
…l.users when finished. Ensures no users are left in the list that weren't in the NAMES response
  • Loading branch information
f0x52 committed Dec 1, 2024
1 parent dd825ef commit 6c659c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/irc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,25 +684,29 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
}
}
if (knownPrefixes.length > 0) {
channel.users.set(match[2], knownPrefixes);
channel.tmpUsers.set(match[2], knownPrefixes);
}
else {
// recombine just in case this server allows weird chars in the nick.
// We know it isn't a mode char.
channel.users.set(match[1] + match[2], '');
channel.tmpUsers.set(match[1] + match[2], '');
}
}
});
// If the channel user list was modified, flush.
if (users.length) {
this.state.flush?.()
}
}

private onReplyNameEnd(message: Message) {
this._casemap(message, 1);
const channel = this.chanData(message.args[1]);
if (channel) {
channel.users.clear();
channel.tmpUsers.forEach((modes, user) => {
channel.users.set(user, modes);
});
channel.tmpUsers.clear();

this.state.flush?.();

this.emit('names', message.args[1], channel.users);
this._send('MODE', message.args[1]);
}
Expand Down Expand Up @@ -1166,6 +1170,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
key: key,
serverName: name,
users: new Map(),
tmpUsers: new Map(),
mode: '',
modeParams: new Map(),
});
Expand Down
1 change: 1 addition & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface ChanData {
* nick => mode
*/
users: Map<string, string>,
tmpUsers: Map<string, string>, // used while processing NAMES replies
mode: string;
modeParams: Map<string, string[]>,
topic?: string;
Expand Down

0 comments on commit 6c659c1

Please sign in to comment.