File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ export class Channel {
3737 readonly #collection: ChannelCollection ;
3838 readonly id : string ;
3939
40+ _typingTimers : Record < string , number > = { } ;
41+
4042 /**
4143 * Construct Channel
4244 * @param collection Collection
Original file line number Diff line number Diff line change @@ -504,15 +504,24 @@ export async function handleEvent(
504504 if ( channel ) {
505505 if ( ! channel . typingIds . has ( event . user ) ) {
506506 channel . typingIds . add ( event . user ) ;
507- } else if ( ! client . channels . isPartial ( event . id ) ) {
508- return ;
509- }
510507
511- client . emit (
512- "channelStartTyping" ,
513- channel ,
514- client . users . getOrPartial ( event . user ) ! ,
515- ) ;
508+ clearTimeout ( channel . _typingTimers [ event . user ] ) ;
509+ channel . _typingTimers [ event . user ] = setTimeout (
510+ ( ) =>
511+ handleEvent (
512+ client ,
513+ { ...event , type : "ChannelStopTyping" } ,
514+ setReady ,
515+ ) ,
516+ 1000 ,
517+ ) as never ;
518+
519+ client . emit (
520+ "channelStartTyping" ,
521+ channel ,
522+ client . users . getOrPartial ( event . user ) ! ,
523+ ) ;
524+ }
516525 }
517526 break ;
518527 }
@@ -521,15 +530,16 @@ export async function handleEvent(
521530 if ( channel ) {
522531 if ( channel . typingIds . has ( event . user ) ) {
523532 channel . typingIds . delete ( event . user ) ;
524- } else if ( ! client . channels . isPartial ( event . id ) ) {
525- return ;
526- }
527533
528- client . emit (
529- "channelStopTyping" ,
530- channel ,
531- client . users . getOrPartial ( event . user ) ! ,
532- ) ;
534+ clearTimeout ( channel . _typingTimers [ event . user ] ) ;
535+ delete channel . _typingTimers [ event . user ] ;
536+
537+ client . emit (
538+ "channelStopTyping" ,
539+ channel ,
540+ client . users . getOrPartial ( event . user ) ! ,
541+ ) ;
542+ }
533543 }
534544 break ;
535545 }
You can’t perform that action at this time.
0 commit comments