@@ -100,9 +100,9 @@ const Tile: React.FC<ITileProps> = ({
100100 children,
101101} ) => {
102102 const cli = useContext ( MatrixClientContext ) ;
103- const [ joinedRoom , setJoinedRoom ] = useState < Room > ( ( ) => {
103+ const [ joinedRoom , setJoinedRoom ] = useState < Room | undefined > ( ( ) => {
104104 const cliRoom = cli . getRoom ( room . room_id ) ;
105- return cliRoom ?. getMyMembership ( ) === "join" ? cliRoom : null ;
105+ return cliRoom ?. getMyMembership ( ) === "join" ? cliRoom : undefined ;
106106 } ) ;
107107 const joinedRoomName = useTypedEventEmitterState ( joinedRoom , RoomEvent . Name , ( room ) => room ?. name ) ;
108108 const name =
@@ -264,9 +264,9 @@ const Tile: React.FC<ITileProps> = ({
264264 </ React . Fragment >
265265 ) ;
266266
267- let childToggle : JSX . Element ;
268- let childSection : JSX . Element ;
269- let onKeyDown : KeyboardEventHandler ;
267+ let childToggle : JSX . Element | undefined ;
268+ let childSection : JSX . Element | undefined ;
269+ let onKeyDown : KeyboardEventHandler | undefined ;
270270 if ( children ) {
271271 // the chevron is purposefully a div rather than a button as it should be ignored for a11y
272272 childToggle = (
@@ -386,32 +386,28 @@ export const showRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: st
386386 } ) ;
387387} ;
388388
389- export const joinRoom = ( cli : MatrixClient , hierarchy : RoomHierarchy , roomId : string ) : Promise < unknown > => {
389+ export const joinRoom = async ( cli : MatrixClient , hierarchy : RoomHierarchy , roomId : string ) : Promise < unknown > => {
390390 // Don't let the user view a room they won't be able to either peek or join:
391391 // fail earlier so they don't have to click back to the directory.
392392 if ( cli . isGuest ( ) ) {
393393 defaultDispatcher . dispatch ( { action : "require_registration" } ) ;
394394 return ;
395395 }
396396
397- const prom = cli . joinRoom ( roomId , {
398- viaServers : Array . from ( hierarchy . viaMap . get ( roomId ) || [ ] ) ,
399- } ) ;
400-
401- prom . then (
402- ( ) => {
403- defaultDispatcher . dispatch < JoinRoomReadyPayload > ( {
404- action : Action . JoinRoomReady ,
405- roomId,
406- metricsTrigger : "SpaceHierarchy" ,
407- } ) ;
408- } ,
409- ( err ) => {
410- SdkContextClass . instance . roomViewStore . showJoinRoomError ( err , roomId ) ;
411- } ,
412- ) ;
397+ try {
398+ await cli . joinRoom ( roomId , {
399+ viaServers : Array . from ( hierarchy . viaMap . get ( roomId ) || [ ] ) ,
400+ } ) ;
401+ } catch ( err ) {
402+ SdkContextClass . instance . roomViewStore . showJoinRoomError ( err , roomId ) ;
403+ return ;
404+ }
413405
414- return prom ;
406+ defaultDispatcher . dispatch < JoinRoomReadyPayload > ( {
407+ action : Action . JoinRoomReady ,
408+ roomId,
409+ metricsTrigger : "SpaceHierarchy" ,
410+ } ) ;
415411} ;
416412
417413interface IHierarchyLevelProps {
@@ -433,7 +429,7 @@ export const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy:
433429 ) ;
434430
435431 // Pick latest room that is actually part of the hierarchy
436- let cliRoom = null ;
432+ let cliRoom : Room | null = null ;
437433 for ( let idx = history . length - 1 ; idx >= 0 ; -- idx ) {
438434 if ( hierarchy . roomMap . get ( history [ idx ] . roomId ) ) {
439435 cliRoom = history [ idx ] ;
@@ -448,7 +444,7 @@ export const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom, hierarchy:
448444 room_type : cliRoom . getType ( ) ,
449445 name : cliRoom . name ,
450446 topic : cliRoom . currentState . getStateEvents ( EventType . RoomTopic , "" ) ?. getContent ( ) . topic ,
451- avatar_url : cliRoom . getMxcAvatarUrl ( ) ,
447+ avatar_url : cliRoom . getMxcAvatarUrl ( ) ?? undefined ,
452448 canonical_alias : cliRoom . getCanonicalAlias ( ) ?? undefined ,
453449 aliases : cliRoom . getAltAliases ( ) ,
454450 world_readable :
@@ -476,7 +472,7 @@ export const HierarchyLevel: React.FC<IHierarchyLevelProps> = ({
476472} ) => {
477473 const cli = useContext ( MatrixClientContext ) ;
478474 const space = cli . getRoom ( root . room_id ) ;
479- const hasPermissions = space ?. currentState . maySendStateEvent ( EventType . SpaceChild , cli . getUserId ( ) ) ;
475+ const hasPermissions = space ?. currentState . maySendStateEvent ( EventType . SpaceChild , cli . getSafeUserId ( ) ) ;
480476
481477 const sortedChildren = sortBy ( root . children_state , ( ev ) => {
482478 return getChildOrder ( ev . content . order , ev . origin_server_ts , ev . state_key ) ;
@@ -579,7 +575,7 @@ export const useRoomHierarchy = (
579575
580576 const loadMore = useCallback (
581577 async ( pageSize ?: number ) : Promise < void > => {
582- if ( hierarchy . loading || ! hierarchy . canLoadMore || hierarchy . noSupport || error ) return ;
578+ if ( ! hierarchy || hierarchy . loading || ! hierarchy . canLoadMore || hierarchy . noSupport || error ) return ;
583579 await hierarchy . load ( pageSize ) . catch ( setError ) ;
584580 setRooms ( hierarchy . rooms ) ;
585581 } ,
@@ -673,7 +669,7 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
673669 onClick = { async ( ) : Promise < void > => {
674670 setRemoving ( true ) ;
675671 try {
676- const userId = cli . getUserId ( ) ;
672+ const userId = cli . getSafeUserId ( ) ;
677673 for ( const [ parentId , childId ] of selectedRelations ) {
678674 await cli . sendStateEvent ( parentId , EventType . SpaceChild , { } , childId ) ;
679675
@@ -759,7 +755,7 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
759755 const visited = new Set < string > ( ) ;
760756 const queue = [ ...directMatches . map ( ( r ) => r . room_id ) ] ;
761757 while ( queue . length ) {
762- const roomId = queue . pop ( ) ;
758+ const roomId = queue . pop ( ) ! ;
763759 visited . add ( roomId ) ;
764760 hierarchy . backRefs . get ( roomId ) ?. forEach ( ( parentId ) => {
765761 if ( ! visited . has ( parentId ) ) {
@@ -797,7 +793,7 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
797793 return ;
798794 }
799795
800- const parentSet = selected . get ( parentId ) ;
796+ const parentSet = selected . get ( parentId ) ! ;
801797 if ( ! parentSet . has ( childId ) ) {
802798 setSelected ( new Map ( selected . set ( parentId , new Set ( [ ...parentSet , childId ] ) ) ) ) ;
803799 return ;
@@ -816,9 +812,9 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
816812 } else {
817813 const hasPermissions =
818814 space ?. getMyMembership ( ) === "join" &&
819- space . currentState . maySendStateEvent ( EventType . SpaceChild , cli . getUserId ( ) ) ;
815+ space . currentState . maySendStateEvent ( EventType . SpaceChild , cli . getSafeUserId ( ) ) ;
820816
821- let results : JSX . Element ;
817+ let results : JSX . Element | undefined ;
822818 if ( filteredRoomSet . size ) {
823819 results = (
824820 < >
@@ -843,7 +839,7 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
843839 ) ;
844840 }
845841
846- let loader : JSX . Element ;
842+ let loader : JSX . Element | undefined ;
847843 if ( hierarchy . canLoadMore ) {
848844 loader = (
849845 < div ref = { loaderRef } >
0 commit comments