@@ -5243,6 +5243,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
52435243 throw new Error ( "could not get thread timeline: no client support" ) ;
52445244 }
52455245
5246+ if ( ! timelineSet . room ) {
5247+ throw new Error ( "could not get thread timeline: not a room timeline" ) ;
5248+ }
5249+
52465250 if ( ! timelineSet . thread ) {
52475251 throw new Error ( "could not get thread timeline: not a thread timeline" ) ;
52485252 }
@@ -5277,14 +5281,14 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
52775281 }
52785282
52795283 const thread = timelineSet . thread ;
5280- const resOlder = await this . fetchRelations (
5284+ const resOlder : IRelationsResponse = await this . fetchRelations (
52815285 timelineSet . room . roomId ,
52825286 thread . id ,
52835287 THREAD_RELATION_TYPE . name ,
52845288 null ,
52855289 { dir : Direction . Backward , from : res . start } ,
52865290 ) ;
5287- const resNewer = await this . fetchRelations (
5291+ const resNewer : IRelationsResponse = await this . fetchRelations (
52885292 timelineSet . room . roomId ,
52895293 thread . id ,
52905294 THREAD_RELATION_TYPE . name ,
@@ -5339,10 +5343,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
53395343 null ,
53405344 { dir : Direction . Backward , from : res . start } ,
53415345 ) ;
5342- const eventsNewer = [ ] ;
5346+ const eventsNewer : IEvent [ ] = [ ] ;
53435347 let nextBatch : Optional < string > = res . end ;
53445348 while ( nextBatch ) {
5345- const resNewer = await this . fetchRelations (
5349+ const resNewer : IRelationsResponse = await this . fetchRelations (
53465350 timelineSet . room . roomId ,
53475351 thread . id ,
53485352 THREAD_RELATION_TYPE . name ,
@@ -5532,7 +5536,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
55325536 // create a shallow copy of LAZY_LOADING_MESSAGES_FILTER,
55335537 // so the timelineFilter doesn't get written into it below
55345538 filter = {
5535- ...filter ,
55365539 ...Filter . LAZY_LOADING_MESSAGES_FILTER ,
55375540 } ;
55385541 }
@@ -5579,7 +5582,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
55795582 const isNotifTimeline = ( eventTimeline . getTimelineSet ( ) === this . notifTimelineSet ) ;
55805583 const room = this . getRoom ( eventTimeline . getRoomId ( ) ) ;
55815584 const isThreadListTimeline = eventTimeline . getTimelineSet ( ) . isThreadTimeline ;
5582- const isThreadTimeline = ( eventTimeline . getTimelineSet ( ) . thread ) ;
5585+ const thread = eventTimeline . getTimelineSet ( ) . thread ;
55835586
55845587 // TODO: we should implement a backoff (as per scrollback()) to deal more
55855588 // nicely with HTTP errors.
@@ -5690,18 +5693,18 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
56905693 eventTimeline . paginationRequests [ dir ] = null ;
56915694 } ) ;
56925695 eventTimeline . paginationRequests [ dir ] = promise ;
5693- } else if ( isThreadTimeline ) {
5696+ } else if ( thread ) {
56945697 const room = this . getRoom ( eventTimeline . getRoomId ( ) ) ;
56955698 if ( ! room ) {
56965699 throw new Error ( "Unknown room " + eventTimeline . getRoomId ( ) ) ;
56975700 }
56985701
56995702 promise = this . fetchRelations (
57005703 eventTimeline . getRoomId ( ) ,
5701- eventTimeline . getTimelineSet ( ) . thread ? .id ,
5704+ thread . id ,
57025705 THREAD_RELATION_TYPE . name ,
57035706 null ,
5704- { dir, limit : opts . limit , from : token } ,
5707+ { dir, limit : opts . limit , from : token ?? undefined } ,
57055708 ) . then ( async ( res ) => {
57065709 const mapper = this . getEventMapper ( ) ;
57075710 const matrixEvents = res . chunk . map ( mapper ) ;
@@ -6933,12 +6936,12 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
69336936 eventType ?: EventType | string | null ,
69346937 opts : IRelationsRequestOpts = { dir : Direction . Backward } ,
69356938 ) : Promise < {
6936- originalEvent : MatrixEvent ;
6939+ originalEvent : MatrixEvent | null ;
69376940 events : MatrixEvent [ ] ;
69386941 nextBatch ?: string ;
69396942 prevBatch ?: string ;
69406943 } > {
6941- const fetchedEventType = this . getEncryptedIfNeededEventType ( roomId , eventType ) ;
6944+ const fetchedEventType = eventType ? this . getEncryptedIfNeededEventType ( roomId , eventType ) : null ;
69426945 const result = await this . fetchRelations (
69436946 roomId ,
69446947 eventId ,
@@ -6962,7 +6965,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
69626965 events = events . filter ( e => e . getSender ( ) === originalEvent . getSender ( ) ) ;
69636966 }
69646967 return {
6965- originalEvent,
6968+ originalEvent : originalEvent ?? null ,
69666969 events,
69676970 nextBatch : result . next_batch ,
69686971 prevBatch : result . prev_batch ,
0 commit comments