@@ -108,18 +108,15 @@ async function getRoomAndEnsureSubscription(matrixRoomId: string, user: IUser):
108108 return room ;
109109}
110110
111- async function getThreadMessageId ( threadRootEventId : string | undefined ) : Promise < string | undefined > {
112- if ( ! threadRootEventId ) {
113- return undefined ;
114- }
115-
111+ async function getThreadMessageId ( threadRootEventId : string ) : Promise < { tmid : string ; tshow : boolean } | undefined > {
116112 const threadRootMessage = await Messages . findOneByFederationId ( threadRootEventId ) ;
117- if ( threadRootMessage ) {
118- logger . debug ( 'Found thread root message:' , { tmid : threadRootMessage . _id , threadRootEventId } ) ;
119- return threadRootMessage . _id ;
113+ if ( ! threadRootMessage ) {
114+ logger . warn ( 'Thread root message not found for event:' , threadRootEventId ) ;
115+ return ;
120116 }
121- logger . warn ( 'Thread root message not found for event:' , threadRootEventId ) ;
122- return undefined ;
117+
118+ const shouldSetTshow = ! threadRootMessage ?. tcount ;
119+ return { tmid : threadRootMessage . _id , tshow : shouldSetTshow } ;
123120}
124121
125122async function handleMediaMessage (
@@ -246,7 +243,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>, serverName:
246243 const isThreadMessage = threadRelation ?. rel_type === 'm.thread' ;
247244 const isQuoteMessage = replyToRelation ?. [ 'm.in_reply_to' ] ?. event_id && ! replyToRelation ?. is_falling_back ;
248245 const threadRootEventId = isThreadMessage ? threadRelation . event_id : undefined ;
249- const tmid = await getThreadMessageId ( threadRootEventId ) ;
246+ const thread = await getThreadMessageId ( threadRootEventId ) ;
250247
251248 const isMediaMessage = Object . values ( fileTypes ) . includes ( msgtype ) ;
252249
@@ -327,7 +324,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>, serverName:
327324 rid : room . _id ,
328325 msg : formatted ,
329326 federation_event_id : data . event_id ,
330- tmid ,
327+ thread ,
331328 } ) ;
332329 return ;
333330 }
@@ -347,7 +344,7 @@ export function message(emitter: Emitter<HomeserverEventSignatures>, serverName:
347344 rid : room . _id ,
348345 msg : formatted ,
349346 federation_event_id : data . event_id ,
350- tmid ,
347+ thread ,
351348 } ) ;
352349 }
353350 } catch ( error ) {
0 commit comments