Skip to content

Commit 849b01b

Browse files
authored
Merge branch 'master' into err-415
2 parents 6ebe772 + 3f2541d commit 849b01b

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

changelog.d/115.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix reconnect loop due to the close listener being called on socket destruction.

changelog.d/116.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix auto reconnect due to event listeners not being called.

changelog.d/117.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix nick changes not being bridged to matrix.

changelog.d/118.bugfix

+1
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.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
filename = "CHANGELOG.md"
44
directory = "changelog.d"
55
issue_format = "[\\#{issue}](https://github.com/matrix-org/node-irc/issues/{issue})"
6+
ignore = ['.gitkeep']
67

78
[[tool.towncrier.type]]
89
directory = "feature"

src/irc.ts

+25-16
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
219219
if (opt.channelPrefixes) {
220220
this.state.supportedState.channel.types = opt.channelPrefixes;
221221
}
222-
this.state.capabilities.once('serverCapabilitesReady', () => {
222+
this.state.capabilities.on('serverCapabilitesReady', () => {
223223
this.onCapsList();
224224
// Flush on capabilities modified
225225
this.state.flush?.();
226226
})
227-
this.state.capabilities.once('userCapabilitesReady', () => {
227+
this.state.capabilities.on('userCapabilitesReady', () => {
228228
this.onCapsConfirmed();
229229
// Flush on capabilities modified
230230
this.state.flush?.();
@@ -630,9 +630,8 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
630630

631631
// finding what channels a user is in
632632
this.state.chans.forEach((nickChannel, channame) => {
633-
const chanUser = message.nick && nickChannel.users.get(message.nick);
634-
if (message.nick && chanUser) {
635-
nickChannel.users.set(message.args[0], chanUser);
633+
if (message.nick && nickChannel.users.has(message.nick)) {
634+
nickChannel.users.set(message.args[0], nickChannel.users.get(message.nick)!);
636635
nickChannel.users.delete(message.nick);
637636
channelsForNick.push(channame);
638637
}
@@ -684,25 +683,29 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
684683
}
685684
}
686685
if (knownPrefixes.length > 0) {
687-
channel.users.set(match[2], knownPrefixes);
686+
channel.tmpUsers.set(match[2], knownPrefixes);
688687
}
689688
else {
690689
// recombine just in case this server allows weird chars in the nick.
691690
// We know it isn't a mode char.
692-
channel.users.set(match[1] + match[2], '');
691+
channel.tmpUsers.set(match[1] + match[2], '');
693692
}
694693
}
695694
});
696-
// If the channel user list was modified, flush.
697-
if (users.length) {
698-
this.state.flush?.()
699-
}
700695
}
701696

702697
private onReplyNameEnd(message: Message) {
703698
this._casemap(message, 1);
704699
const channel = this.chanData(message.args[1]);
705700
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+
706709
this.emit('names', message.args[1], channel.users);
707710
this._send('MODE', message.args[1]);
708711
}
@@ -1166,6 +1169,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
11661169
key: key,
11671170
serverName: name,
11681171
users: new Map(),
1172+
tmpUsers: new Map(),
11691173
mode: '',
11701174
modeParams: new Map(),
11711175
});
@@ -1272,6 +1276,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
12721276

12731277
// destroy old socket before allocating a new one
12741278
if (this.isOurSocket && this.conn) {
1279+
this.unbindListeners();
12751280
this.conn.destroy();
12761281
this.conn = undefined;
12771282
}
@@ -1425,6 +1430,14 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
14251430
});
14261431
}
14271432

1433+
private unbindListeners() {
1434+
(
1435+
['data', 'end', 'close', 'timeout', 'error'] as (keyof IrcConnectionEventsMap)[]
1436+
).forEach(evtType => {
1437+
this.conn?.removeAllListeners(evtType);
1438+
});
1439+
}
1440+
14281441
private reconnect(retryCount: number) {
14291442
if (!this.isOurSocket) {
14301443
// Cannot reconnect if the socket is not ours.
@@ -1455,11 +1468,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
14551468
*/
14561469
public destroy() {
14571470
util.log('Destroying connection');
1458-
(
1459-
['data', 'end', 'close', 'timeout', 'error'] as (keyof IrcConnectionEventsMap)[]
1460-
).forEach(evtType => {
1461-
this.conn?.removeAllListeners(evtType);
1462-
});
1471+
this.unbindListeners();
14631472
if (this.isOurSocket) {
14641473
this.disconnect();
14651474
}

src/state.ts

+1
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)