@@ -590,27 +590,27 @@ export function createUnread({
590590 }
591591 // Names/previews do not affect unread. Read membership once, without a
592592 // roster scan for every channel, and retain only the invalidation inputs.
593- const types = ( ) =>
593+ const types = ( list : ReturnType < ChannelQueries [ "list" ] > ) =>
594594 new Map (
595- channels
596- . list ( )
597- . channels . filter (
595+ list . channels
596+ . filter (
598597 ( channel ) => ! channel . cached && channel . members ?. includes ( viewer ) ,
599598 )
600599 . map ( ( channel ) => [ channel . id , channel . channelType ] ) ,
601600 ) ;
602- const cachedIds = ( ) =>
601+ const cachedIds = ( list : ReturnType < ChannelQueries [ "list" ] > ) =>
603602 new Set (
604- channels
605- . list ( )
606- . channels . filter ( ( channel ) => channel . cached )
603+ list . channels
604+ . filter ( ( channel ) => channel . cached )
607605 . map ( ( channel ) => channel . id ) ,
608606 ) ;
609- let cachedChannels = cachedIds ( ) ;
610- let channelTypes = types ( ) ;
607+ const initialList = channels . list ( ) ;
608+ let cachedChannels = cachedIds ( initialList ) ;
609+ let channelTypes = types ( initialList ) ;
611610 let accessKey = [ ...channelTypes . keys ( ) ] . sort ( ) . join ( "," ) ;
612611 const stopChannels = channels . subscribeList ( ( ) => {
613- const nextTypes = types ( ) ;
612+ const list = channels . list ( ) ;
613+ const nextTypes = types ( list ) ;
614614 const next = [ ...nextTypes . keys ( ) ] . sort ( ) . join ( "," ) ;
615615 const changed = new Set (
616616 [ ...nextTypes ] . flatMap ( ( [ id , type ] ) =>
@@ -620,7 +620,7 @@ export function createUnread({
620620 const confirmed = [ ...nextTypes . keys ( ) ] . some ( ( id ) =>
621621 cachedChannels . has ( id ) ,
622622 ) ;
623- cachedChannels = cachedIds ( ) ;
623+ cachedChannels = cachedIds ( list ) ;
624624 channelTypes = nextTypes ;
625625 if ( next === accessKey ) {
626626 if ( changed . size ) publish ( changed ) ;
0 commit comments