@@ -132,7 +132,7 @@ if (DEBUG) {
132132}
133133
134134interface IRoomProps {
135- threepidInvite : IThreepidInvite ;
135+ threepidInvite ? : IThreepidInvite ;
136136 oobData ?: IOOBData ;
137137
138138 resizeNotifier : ResizeNotifier ;
@@ -606,11 +606,11 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
606606 return ;
607607 }
608608
609- const roomId = this . context . roomViewStore . getRoomId ( ) ;
610- const room = this . context . client . getRoom ( roomId ) ;
609+ const roomId = this . context . roomViewStore . getRoomId ( ) ?? null ;
610+ const room = this . context . client ? .getRoom ( roomId ?? undefined ) ?? undefined ;
611611
612612 const newState : Partial < IRoomState > = {
613- roomId,
613+ roomId : roomId ?? undefined ,
614614 roomAlias : this . context . roomViewStore . getRoomAlias ( ) ,
615615 roomLoading : this . context . roomViewStore . isRoomLoading ( ) ,
616616 roomLoadError : this . context . roomViewStore . getRoomLoadError ( ) ,
@@ -624,8 +624,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
624624 showAvatarChanges : SettingsStore . getValue ( "showAvatarChanges" , roomId ) ,
625625 showDisplaynameChanges : SettingsStore . getValue ( "showDisplaynameChanges" , roomId ) ,
626626 wasContextSwitch : this . context . roomViewStore . getWasContextSwitch ( ) ,
627- mainSplitContentType : room === null ? undefined : this . getMainSplitContentType ( room ) ,
628- initialEventId : null , // default to clearing this, will get set later in the method if needed
627+ mainSplitContentType : room ? this . getMainSplitContentType ( room ) : undefined ,
628+ initialEventId : undefined , // default to clearing this, will get set later in the method if needed
629629 showRightPanel : this . context . rightPanelStore . isOpenForRoom ( roomId ) ,
630630 activeCall : CallStore . instance . getActiveCall ( roomId ) ,
631631 } ;
@@ -655,12 +655,11 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
655655 // The rest will be lost for now, until the aggregation API on the server
656656 // becomes available to fetch a whole thread
657657 if ( ! initialEvent ) {
658- initialEvent = await fetchInitialEvent ( this . context . client , roomId , initialEventId ) ;
658+ initialEvent = ( await fetchInitialEvent ( this . context . client , roomId , initialEventId ) ) ?? undefined ;
659659 }
660660
661- // If we have an initial event, we want to reset the event pixel offset to ensure it ends up
662- // visible
663- newState . initialEventPixelOffset = null ;
661+ // If we have an initial event, we want to reset the event pixel offset to ensure it ends up visible
662+ newState . initialEventPixelOffset = undefined ;
664663
665664 const thread = initialEvent ?. getThread ( ) ;
666665 if ( thread && ! initialEvent ?. isThreadRoot ) {
@@ -709,7 +708,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
709708
710709 if ( ! initial && this . state . shouldPeek && ! newState . shouldPeek ) {
711710 // Stop peeking because we have joined this room now
712- this . context . client . stopPeeking ( ) ;
711+ this . context . client ? .stopPeeking ( ) ;
713712 }
714713
715714 // Temporary logging to diagnose https://github.com/vector-im/element-web/issues/4307
@@ -825,7 +824,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
825824 }
826825 }
827826
828- private setupRoom ( room : Room , roomId : string , joining : boolean , shouldPeek : boolean ) : void {
827+ private setupRoom ( room : Room | undefined , roomId : string | undefined , joining : boolean , shouldPeek : boolean ) : void {
829828 // if this is an unknown room then we're in one of three states:
830829 // - This is a room we can peek into (search engine) (we can /peek)
831830 // - This is a room we can publicly join or were invited to. (we can /join)
@@ -1504,7 +1503,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15041503
15051504 private updateDMState ( ) : void {
15061505 const room = this . state . room ;
1507- if ( room . getMyMembership ( ) != "join" ) {
1506+ if ( room ? .getMyMembership ( ) != = "join" ) {
15081507 return ;
15091508 }
15101509 const dmInviter = room . getDMInviter ( ) ;
@@ -1564,7 +1563,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15641563 ) ;
15651564
15661565 private onMessageListScroll = ( ) : void => {
1567- if ( this . messagePanel . isAtEndOfLiveTimeline ( ) ) {
1566+ if ( this . messagePanel ? .isAtEndOfLiveTimeline ( ) ) {
15681567 this . setState ( {
15691568 numUnreadMessages : 0 ,
15701569 atEndOfLiveTimeline : true ,
@@ -1740,7 +1739,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
17401739 this . setState (
17411740 {
17421741 timelineRenderingType : TimelineRenderingType . Room ,
1743- search : null ,
1742+ search : undefined ,
17441743 } ,
17451744 resolve ,
17461745 ) ;
@@ -1760,20 +1759,20 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
17601759 } ) ;
17611760 } else {
17621761 // Otherwise we have to jump manually
1763- this . messagePanel . jumpToLiveTimeline ( ) ;
1762+ this . messagePanel ? .jumpToLiveTimeline ( ) ;
17641763 dis . fire ( Action . FocusSendMessageComposer ) ;
17651764 }
17661765 } ;
17671766
17681767 // jump up to wherever our read marker is
17691768 private jumpToReadMarker = ( ) : void => {
1770- this . messagePanel . jumpToReadMarker ( ) ;
1769+ this . messagePanel ? .jumpToReadMarker ( ) ;
17711770 } ;
17721771
17731772 // update the read marker to match the read-receipt
17741773 private forgetReadMarker = ( ev : ButtonEvent ) : void => {
17751774 ev . stopPropagation ( ) ;
1776- this . messagePanel . forgetReadMarker ( ) ;
1775+ this . messagePanel ? .forgetReadMarker ( ) ;
17771776 } ;
17781777
17791778 // decide whether or not the top 'unread messages' bar should be shown
@@ -1791,7 +1790,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
17911790 // get the current scroll position of the room, so that it can be
17921791 // restored when we switch back to it.
17931792 //
1794- private getScrollState ( ) : ScrollState {
1793+ private getScrollState ( ) : ScrollState | null {
17951794 const messagePanel = this . messagePanel ;
17961795 if ( ! messagePanel ) return null ;
17971796
@@ -1845,7 +1844,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
18451844 * We pass it down to the scroll panel.
18461845 */
18471846 public handleScrollKey = ( ev : React . KeyboardEvent | KeyboardEvent ) : void => {
1848- let panel : ScrollPanel | TimelinePanel ;
1847+ let panel : ScrollPanel | TimelinePanel | undefined ;
18491848 if ( this . searchResultsPanel . current ) {
18501849 panel = this . searchResultsPanel . current ;
18511850 } else if ( this . messagePanel ) {
@@ -1858,7 +1857,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
18581857 /**
18591858 * get any current call for this room
18601859 */
1861- private getCallForRoom ( ) : MatrixCall {
1860+ private getCallForRoom ( ) : MatrixCall | null {
18621861 if ( ! this . state . room ) {
18631862 return null ;
18641863 }
@@ -1920,7 +1919,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
19201919 }
19211920
19221921 private renderLocalRoomCreateLoader ( localRoom : LocalRoom ) : ReactElement {
1923- const names = this . state . room . getDefaultRoomName ( this . context . client . getUserId ( ) ) ;
1922+ const names = this . state . room . getDefaultRoomName ( this . context . client . getSafeUserId ( ) ) ;
19241923 return (
19251924 < RoomContext . Provider value = { this . state } >
19261925 < LocalRoomCreateLoader localRoom = { localRoom } names = { names } resizeNotifier = { this . props . resizeNotifier } />
@@ -1992,7 +1991,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
19921991 </ div >
19931992 ) ;
19941993 } else {
1995- let inviterName = undefined ;
1994+ let inviterName : string | undefined ;
19961995 if ( this . props . oobData ) {
19971996 inviterName = this . props . oobData . inviterName ;
19981997 }
@@ -2058,12 +2057,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
20582057 </ ErrorBoundary >
20592058 ) ;
20602059 } else {
2061- const myUserId = this . context . client . credentials . userId ;
2060+ const myUserId = this . context . client . getSafeUserId ( ) ;
20622061 const myMember = this . state . room . getMember ( myUserId ) ;
20632062 const inviteEvent = myMember ? myMember . events . member : null ;
20642063 let inviterName = _t ( "Unknown" ) ;
20652064 if ( inviteEvent ) {
2066- inviterName = inviteEvent . sender ? inviteEvent . sender . name : inviteEvent . getSender ( ) ;
2065+ inviterName = inviteEvent . sender ?. name ?? inviteEvent . getSender ( ) ;
20672066 }
20682067
20692068 // We deliberately don't try to peek into invites, even if we have permission to peek
@@ -2140,7 +2139,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
21402139 const showRoomUpgradeBar =
21412140 roomVersionRecommendation &&
21422141 roomVersionRecommendation . needsUpgrade &&
2143- this . state . room . userMayUpgradeRoom ( this . context . client . credentials . userId ) ;
2142+ this . state . room . userMayUpgradeRoom ( this . context . client . getSafeUserId ( ) ) ;
21442143
21452144 const hiddenHighlightCount = this . getHiddenHighlightCount ( ) ;
21462145
@@ -2160,7 +2159,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
21602159 } else if ( myMembership !== "join" ) {
21612160 // We do have a room object for this room, but we're not currently in it.
21622161 // We may have a 3rd party invite to it.
2163- let inviterName = undefined ;
2162+ let inviterName : string | undefined ;
21642163 if ( this . props . oobData ) {
21652164 inviterName = this . props . oobData . inviterName ;
21662165 }
@@ -2207,6 +2206,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
22072206 space = { this . state . room }
22082207 justCreatedOpts = { this . props . justCreatedOpts }
22092208 resizeNotifier = { this . props . resizeNotifier }
2209+ permalinkCreator = { this . permalinkCreator }
22102210 onJoinButtonClicked = { this . onJoinButtonClicked }
22112211 onRejectButtonClicked = {
22122212 this . props . threepidInvite
@@ -2220,7 +2220,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
22202220 const auxPanel = (
22212221 < AuxPanel
22222222 room = { this . state . room }
2223- userId = { this . context . client . credentials . userId }
2223+ userId = { this . context . client . getSafeUserId ( ) }
22242224 showApps = { this . state . showApps }
22252225 resizeNotifier = { this . props . resizeNotifier }
22262226 >
@@ -2330,7 +2330,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
23302330 permalinkCreator = { this . permalinkCreator }
23312331 e2eStatus = { this . state . e2eStatus }
23322332 />
2333- ) : null ;
2333+ ) : undefined ;
23342334
23352335 const timelineClasses = classNames ( "mx_RoomView_timeline" , {
23362336 mx_RoomView_timeline_rr_enabled : this . state . showReadReceipts ,
@@ -2344,14 +2344,16 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
23442344 const showChatEffects = SettingsStore . getValue ( "showChatEffects" ) ;
23452345
23462346 let mainSplitBody : JSX . Element | undefined ;
2347- let mainSplitContentClassName : string ;
2347+ let mainSplitContentClassName : string | undefined ;
23482348 // Decide what to show in the main split
23492349 switch ( this . state . mainSplitContentType ) {
23502350 case MainSplitContentType . Timeline :
23512351 mainSplitContentClassName = "mx_MainSplit_timeline" ;
23522352 mainSplitBody = (
23532353 < >
2354- < Measured sensor = { this . roomViewBody . current } onMeasurement = { this . onMeasurement } />
2354+ { this . roomViewBody . current && (
2355+ < Measured sensor = { this . roomViewBody . current } onMeasurement = { this . onMeasurement } />
2356+ ) }
23552357 { auxPanel }
23562358 < div className = { timelineClasses } >
23572359 < FileDropTarget parent = { this . roomView . current } onFileDrop = { this . onFileDrop } />
@@ -2372,7 +2374,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
23722374 < >
23732375 < AppsDrawer
23742376 room = { this . state . room }
2375- userId = { this . context . client . credentials . userId }
2377+ userId = { this . context . client . getSafeUserId ( ) }
23762378 resizeNotifier = { this . props . resizeNotifier }
23772379 showApps = { true }
23782380 />
@@ -2426,7 +2428,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
24262428 onAppsClick = null ;
24272429 onForgetClick = null ;
24282430 onSearchClick = null ;
2429- if ( this . state . room . canInvite ( this . context . client . credentials . userId ) ) {
2431+ if ( this . state . room . canInvite ( this . context . client . getSafeUserId ( ) ) ) {
24302432 onInviteClick = this . onInviteClick ;
24312433 }
24322434 viewingCall = true ;
0 commit comments