@@ -38,27 +38,33 @@ export async function reconcileChatStreamMarkers(
3838 const results = new Map < string , ReconciledChatStreamMarker > ( )
3939
4040 for ( const candidate of candidates ) {
41+ if ( candidate . streamId === null ) {
42+ results . set ( candidate . chatId , {
43+ chatId : candidate . chatId ,
44+ streamId : null ,
45+ status : 'inactive' ,
46+ } )
47+ continue
48+ }
4149 results . set ( candidate . chatId , {
4250 chatId : candidate . chatId ,
4351 streamId : candidate . streamId ,
44- status : candidate . streamId ? 'unknown' : 'inactive ',
52+ status : 'unknown' ,
4553 } )
4654 }
4755
48- if ( candidates . length === 0 ) {
56+ const candidatesWithMarkers = candidates . filter ( ( candidate ) => candidate . streamId !== null )
57+ if ( candidatesWithMarkers . length === 0 ) {
4958 return results
5059 }
5160
5261 const { status, ownersByChatId } = await getChatStreamLockOwners (
53- candidates . map ( ( candidate ) => candidate . chatId )
62+ candidatesWithMarkers . map ( ( candidate ) => candidate . chatId )
5463 )
5564
56- for ( const candidate of candidates ) {
65+ for ( const candidate of candidatesWithMarkers ) {
5766 const owner = ownersByChatId . get ( candidate . chatId )
58- if (
59- owner &&
60- ( status === 'verified' || owner === candidate . streamId || candidate . streamId === null )
61- ) {
67+ if ( owner && ( status === 'verified' || owner === candidate . streamId ) ) {
6268 results . set ( candidate . chatId , {
6369 chatId : candidate . chatId ,
6470 streamId : owner ,
@@ -67,7 +73,7 @@ export async function reconcileChatStreamMarkers(
6773 continue
6874 }
6975
70- if ( status === 'verified' && candidate . streamId !== null ) {
76+ if ( status === 'verified' ) {
7177 results . set ( candidate . chatId , {
7278 chatId : candidate . chatId ,
7379 streamId : null ,
@@ -79,7 +85,7 @@ export async function reconcileChatStreamMarkers(
7985 results . set ( candidate . chatId , {
8086 chatId : candidate . chatId ,
8187 streamId : candidate . streamId ,
82- status : candidate . streamId ? 'unknown' : 'inactive ',
88+ status : 'unknown' ,
8389 } )
8490 }
8591
0 commit comments