From 6c659c1cbc2ae123fa65297c429303f9f4d595c2 Mon Sep 17 00:00:00 2001 From: f0x Date: Sun, 1 Dec 2024 20:39:39 +0100 Subject: [PATCH 1/2] 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 --- src/irc.ts | 17 +++++++++++------ src/state.ts | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/irc.ts b/src/irc.ts index 06669642..2d991df0 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -684,25 +684,29 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter 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]); } @@ -1166,6 +1170,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter mode */ users: Map, + tmpUsers: Map, // used while processing NAMES replies mode: string; modeParams: Map, topic?: string; From 61f376be0530922737e175cd1e7a620928af7c79 Mon Sep 17 00:00:00 2001 From: f0x Date: Sun, 1 Dec 2024 20:53:26 +0100 Subject: [PATCH 2/2] changelog entry --- changelog.d/118.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/118.bugfix diff --git a/changelog.d/118.bugfix b/changelog.d/118.bugfix new file mode 100644 index 00000000..d8898aca --- /dev/null +++ b/changelog.d/118.bugfix @@ -0,0 +1 @@ +Ensure channel.users is an accurate representation of the NAMES response after updates, removing stale users. \ No newline at end of file