Skip to content

Commit 6c659c1

Browse files
committed
Store NAMES replies in separate Map while processing, override channel.users when finished. Ensures no users are left in the list that weren't in the NAMES response
1 parent dd825ef commit 6c659c1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/irc.ts

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

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

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)