@@ -219,12 +219,12 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
219
219
if ( opt . channelPrefixes ) {
220
220
this . state . supportedState . channel . types = opt . channelPrefixes ;
221
221
}
222
- this . state . capabilities . once ( 'serverCapabilitesReady' , ( ) => {
222
+ this . state . capabilities . on ( 'serverCapabilitesReady' , ( ) => {
223
223
this . onCapsList ( ) ;
224
224
// Flush on capabilities modified
225
225
this . state . flush ?.( ) ;
226
226
} )
227
- this . state . capabilities . once ( 'userCapabilitesReady' , ( ) => {
227
+ this . state . capabilities . on ( 'userCapabilitesReady' , ( ) => {
228
228
this . onCapsConfirmed ( ) ;
229
229
// Flush on capabilities modified
230
230
this . state . flush ?.( ) ;
@@ -630,9 +630,8 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
630
630
631
631
// finding what channels a user is in
632
632
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 ) ! ) ;
636
635
nickChannel . users . delete ( message . nick ) ;
637
636
channelsForNick . push ( channame ) ;
638
637
}
@@ -684,25 +683,29 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
684
683
}
685
684
}
686
685
if ( knownPrefixes . length > 0 ) {
687
- channel . users . set ( match [ 2 ] , knownPrefixes ) ;
686
+ channel . tmpUsers . set ( match [ 2 ] , knownPrefixes ) ;
688
687
}
689
688
else {
690
689
// recombine just in case this server allows weird chars in the nick.
691
690
// We know it isn't a mode char.
692
- channel . users . set ( match [ 1 ] + match [ 2 ] , '' ) ;
691
+ channel . tmpUsers . set ( match [ 1 ] + match [ 2 ] , '' ) ;
693
692
}
694
693
}
695
694
} ) ;
696
- // If the channel user list was modified, flush.
697
- if ( users . length ) {
698
- this . state . flush ?.( )
699
- }
700
695
}
701
696
702
697
private onReplyNameEnd ( message : Message ) {
703
698
this . _casemap ( message , 1 ) ;
704
699
const channel = this . chanData ( message . args [ 1 ] ) ;
705
700
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
+
706
709
this . emit ( 'names' , message . args [ 1 ] , channel . users ) ;
707
710
this . _send ( 'MODE' , message . args [ 1 ] ) ;
708
711
}
@@ -1166,6 +1169,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
1166
1169
key : key ,
1167
1170
serverName : name ,
1168
1171
users : new Map ( ) ,
1172
+ tmpUsers : new Map ( ) ,
1169
1173
mode : '' ,
1170
1174
modeParams : new Map ( ) ,
1171
1175
} ) ;
@@ -1272,6 +1276,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
1272
1276
1273
1277
// destroy old socket before allocating a new one
1274
1278
if ( this . isOurSocket && this . conn ) {
1279
+ this . unbindListeners ( ) ;
1275
1280
this . conn . destroy ( ) ;
1276
1281
this . conn = undefined ;
1277
1282
}
@@ -1425,6 +1430,14 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
1425
1430
} ) ;
1426
1431
}
1427
1432
1433
+ private unbindListeners ( ) {
1434
+ (
1435
+ [ 'data' , 'end' , 'close' , 'timeout' , 'error' ] as ( keyof IrcConnectionEventsMap ) [ ]
1436
+ ) . forEach ( evtType => {
1437
+ this . conn ?. removeAllListeners ( evtType ) ;
1438
+ } ) ;
1439
+ }
1440
+
1428
1441
private reconnect ( retryCount : number ) {
1429
1442
if ( ! this . isOurSocket ) {
1430
1443
// Cannot reconnect if the socket is not ours.
@@ -1455,11 +1468,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
1455
1468
*/
1456
1469
public destroy ( ) {
1457
1470
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 ( ) ;
1463
1472
if ( this . isOurSocket ) {
1464
1473
this . disconnect ( ) ;
1465
1474
}
0 commit comments