Skip to content

Commit 3f2541d

Browse files
authored
Merge pull request #118 from f0x52/clear-names
Ensure channel.users is an accurate representation of the NAMES response after updating by removing stale users
2 parents 1a4e183 + 5a9b8d8 commit 3f2541d

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

changelog.d/118.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure channel.users is an accurate representation of the NAMES response after updates, removing stale users.

src/irc.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,25 +683,29 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
683683
}
684684
}
685685
if (knownPrefixes.length > 0) {
686-
channel.users.set(match[2], knownPrefixes);
686+
channel.tmpUsers.set(match[2], knownPrefixes);
687687
}
688688
else {
689689
// recombine just in case this server allows weird chars in the nick.
690690
// We know it isn't a mode char.
691-
channel.users.set(match[1] + match[2], '');
691+
channel.tmpUsers.set(match[1] + match[2], '');
692692
}
693693
}
694694
});
695-
// If the channel user list was modified, flush.
696-
if (users.length) {
697-
this.state.flush?.()
698-
}
699695
}
700696

701697
private onReplyNameEnd(message: Message) {
702698
this._casemap(message, 1);
703699
const channel = this.chanData(message.args[1]);
704700
if (channel) {
701+
channel.users.clear();
702+
channel.tmpUsers.forEach((modes, user) => {
703+
channel.users.set(user, modes);
704+
});
705+
channel.tmpUsers.clear();
706+
707+
this.state.flush?.();
708+
705709
this.emit('names', message.args[1], channel.users);
706710
this._send('MODE', message.args[1]);
707711
}
@@ -1165,6 +1169,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
11651169
key: key,
11661170
serverName: name,
11671171
users: new Map(),
1172+
tmpUsers: new Map(),
11681173
mode: '',
11691174
modeParams: new Map(),
11701175
});

src/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface ChanData {
9090
* nick => mode
9191
*/
9292
users: Map<string, string>,
93+
tmpUsers: Map<string, string>, // used while processing NAMES replies
9394
mode: string;
9495
modeParams: Map<string, string[]>,
9596
topic?: string;

0 commit comments

Comments
 (0)