Skip to content

Commit

Permalink
Merge pull request #118 from f0x52/clear-names
Browse files Browse the repository at this point in the history
Ensure channel.users is an accurate representation of the NAMES response after updating by removing stale users
  • Loading branch information
tadzik authored Feb 25, 2025
2 parents 1a4e183 + 5a9b8d8 commit 3f2541d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/118.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure channel.users is an accurate representation of the NAMES response after updates, removing stale users.
17 changes: 11 additions & 6 deletions src/irc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,25 +683,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 @@ -1165,6 +1169,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 3f2541d

Please sign in to comment.