Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure channel.users is an accurate representation of the NAMES response after updating by removing stale users #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Loading