@@ -30,7 +30,6 @@ import { ClientEvent } from "matrix-js-sdk/src/client";
3030import { Thread , ThreadEvent } from "matrix-js-sdk/src/models/thread" ;
3131import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts" ;
3232import { MatrixError } from "matrix-js-sdk/src/http-api" ;
33- import { ReadReceipt } from "matrix-js-sdk/src/models/read-receipt" ;
3433import { Relations } from "matrix-js-sdk/src/models/relations" ;
3534
3635import SettingsStore from "../../settings/SettingsStore" ;
@@ -515,23 +514,22 @@ class TimelinePanel extends React.Component<IProps, IState> {
515514
516515 if ( count > 0 ) {
517516 debuglog ( "Unpaginating" , count , "in direction" , dir ) ;
518- this . timelineWindow . unpaginate ( count , backwards ) ;
517+ this . timelineWindow ? .unpaginate ( count , backwards ) ;
519518
520519 const { events, liveEvents, firstVisibleEventIndex } = this . getEvents ( ) ;
521520 this . buildLegacyCallEventGroupers ( events ) ;
522- const newState : Partial < IState > = {
521+ this . setState ( {
523522 events,
524523 liveEvents,
525524 firstVisibleEventIndex,
526- } ;
525+ } ) ;
527526
528527 // We can now paginate in the unpaginated direction
529528 if ( backwards ) {
530- newState . canBackPaginate = true ;
529+ this . setState ( { canBackPaginate : true } ) ;
531530 } else {
532- newState . canForwardPaginate = true ;
531+ this . setState ( { canForwardPaginate : true } ) ;
533532 }
534- this . setState < null > ( newState ) ;
535533 }
536534 } ;
537535
@@ -636,6 +634,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
636634 private doManageReadMarkers = debounce (
637635 ( ) => {
638636 const rmPosition = this . getReadMarkerPosition ( ) ;
637+ if ( rmPosition === null ) return ;
639638 // we hide the read marker when it first comes onto the screen, but if
640639 // it goes back off the top of the screen (presumably because the user
641640 // clicks on the 'jump to bottom' button), we need to re-enable it.
@@ -1125,7 +1124,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
11251124 return ;
11261125 }
11271126 const lastDisplayedEvent = this . state . events [ lastDisplayedIndex ] ;
1128- this . setReadMarker ( lastDisplayedEvent . getId ( ) , lastDisplayedEvent . getTs ( ) ) ;
1127+ this . setReadMarker ( lastDisplayedEvent . getId ( ) ! , lastDisplayedEvent . getTs ( ) ) ;
11291128
11301129 // the read-marker should become invisible, so that if the user scrolls
11311130 // down, they don't see it.
@@ -1141,7 +1140,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
11411140
11421141 // advance the read marker past any events we sent ourselves.
11431142 private advanceReadMarkerPastMyEvents ( ) : void {
1144- if ( ! this . props . manageReadMarkers ) return ;
1143+ if ( ! this . props . manageReadMarkers || ! this . timelineWindow ) return ;
11451144
11461145 // we call `timelineWindow.getEvents()` rather than using
11471146 // `this.state.liveEvents`, because React batches the update to the
@@ -1171,7 +1170,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
11711170 i -- ;
11721171
11731172 const ev = events [ i ] ;
1174- this . setReadMarker ( ev . getId ( ) , ev . getTs ( ) ) ;
1173+ this . setReadMarker ( ev . getId ( ) ! , ev . getTs ( ) ) ;
11751174 }
11761175
11771176 /* jump down to the bottom of this room, where new events are arriving
@@ -1280,6 +1279,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
12801279 public getReadMarkerPosition = ( ) : number | null => {
12811280 if ( ! this . props . manageReadMarkers ) return null ;
12821281 if ( ! this . messagePanel . current ) return null ;
1282+ if ( ! this . props . timelineSet . room ) return null ;
12831283
12841284 const ret = this . messagePanel . current . getReadMarkerPosition ( ) ;
12851285 if ( ret !== null ) {
@@ -1629,7 +1629,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
16291629 return 0 ;
16301630 }
16311631
1632- const userId = cli . credentials . userId ;
1632+ const userId = cli . getSafeUserId ( ) ;
16331633
16341634 // get the user's membership at the last event by getting the timeline
16351635 // that the event belongs to, and traversing the timeline looking for
@@ -1648,7 +1648,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
16481648 continue ;
16491649 }
16501650
1651- userMembership = timeline . getState ( EventTimeline . FORWARDS ) . getMember ( userId ) ?. membership ?? "leave" ;
1651+ userMembership = timeline . getState ( EventTimeline . FORWARDS ) ? .getMember ( userId ) ?. membership ?? "leave" ;
16521652 const timelineEvents = timeline . getEvents ( ) ;
16531653 for ( let j = timelineEvents . length - 1 ; j >= 0 ; j -- ) {
16541654 const event = timelineEvents [ j ] ;
@@ -1769,7 +1769,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
17691769 for ( let i = this . state . liveEvents . length - 1 ; i >= 0 ; -- i ) {
17701770 const ev = this . state . liveEvents [ i ] ;
17711771
1772- const node = messagePanel . getNodeForEventId ( ev . getId ( ) ) ;
1772+ const node = messagePanel . getNodeForEventId ( ev . getId ( ) ! ) ;
17731773 const isInView = isNodeInView ( node ) ;
17741774
17751775 // when we've reached the first visible event, and the previous
@@ -1829,8 +1829,8 @@ class TimelinePanel extends React.Component<IProps, IState> {
18291829 }
18301830
18311831 const myUserId = client . getSafeUserId ( ) ;
1832- const receiptStore : ReadReceipt < any , any > = this . props . timelineSet . thread ?? this . props . timelineSet . room ;
1833- return receiptStore ?. getEventReadUpTo ( myUserId , ignoreSynthesized ) ;
1832+ const receiptStore = this . props . timelineSet . thread ?? this . props . timelineSet . room ;
1833+ return receiptStore ?. getEventReadUpTo ( myUserId , ignoreSynthesized ) ?? null ;
18341834 }
18351835
18361836 private setReadMarker ( eventId : string | null , eventTs : number , inhibitSetState = false ) : void {
@@ -1924,7 +1924,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
19241924 // If the state is PREPARED or CATCHUP, we're still waiting for the js-sdk to sync with
19251925 // the HS and fetch the latest events, so we are effectively forward paginating.
19261926 const forwardPaginating =
1927- this . state . forwardPaginating || [ "PREPARED" , "CATCHUP" ] . includes ( this . state . clientSyncState ) ;
1927+ this . state . forwardPaginating || [ "PREPARED" , "CATCHUP" ] . includes ( this . state . clientSyncState ! ) ;
19281928 const events = this . state . firstVisibleEventIndex
19291929 ? this . state . events . slice ( this . state . firstVisibleEventIndex )
19301930 : this . state . events ;
@@ -1985,7 +1985,7 @@ function serializeEventIdsFromTimelineSets(timelineSets: EventTimelineSet[]): {
19851985 // Add a special label when it is the live timeline so we can tell
19861986 // it apart from the others
19871987 const isLiveTimeline = timeline === liveTimeline ;
1988- timelineMap [ isLiveTimeline ? "liveTimeline" : `${ index } ` ] = timeline . getEvents ( ) . map ( ( ev ) => ev . getId ( ) ) ;
1988+ timelineMap [ isLiveTimeline ? "liveTimeline" : `${ index } ` ] = timeline . getEvents ( ) . map ( ( ev ) => ev . getId ( ) ! ) ;
19891989 } ) ;
19901990
19911991 return timelineMap ;
0 commit comments