@@ -99,7 +99,7 @@ interface IState {
9999 hasPermissionToLoad : boolean ;
100100 // Wait for user profile load to display correct name
101101 isUserProfileReady : boolean ;
102- error : Error ;
102+ error : Error | null ;
103103 menuDisplayed : boolean ;
104104 requiresClient : boolean ;
105105}
@@ -124,7 +124,7 @@ export default class AppTile extends React.Component<IProps, IState> {
124124 private iframe : HTMLIFrameElement ; // ref to the iframe (callback style)
125125 private allowedWidgetsWatchRef : string ;
126126 private persistKey : string ;
127- private sgWidget : StopGapWidget ;
127+ private sgWidget : StopGapWidget | null ;
128128 private dispatcherRef : string ;
129129 private unmounted : boolean ;
130130
@@ -202,7 +202,7 @@ export default class AppTile extends React.Component<IProps, IState> {
202202 private determineInitialRequiresClientState ( ) : boolean {
203203 try {
204204 const mockWidget = new ElementWidget ( this . props . app ) ;
205- const widgetApi = WidgetMessagingStore . instance . getMessaging ( mockWidget , this . props . room . roomId ) ;
205+ const widgetApi = WidgetMessagingStore . instance . getMessaging ( mockWidget , this . props . room ? .roomId ) ;
206206 if ( widgetApi ) {
207207 // Load value from existing API to prevent resetting the requiresClient value on layout changes.
208208 return widgetApi . hasCapability ( ElementWidgetCapabilities . RequiresClient ) ;
@@ -310,9 +310,9 @@ export default class AppTile extends React.Component<IProps, IState> {
310310 }
311311
312312 private setupSgListeners ( ) : void {
313- this . sgWidget . on ( "preparing" , this . onWidgetPreparing ) ;
313+ this . sgWidget ? .on ( "preparing" , this . onWidgetPreparing ) ;
314314 // emits when the capabilities have been set up or changed
315- this . sgWidget . on ( "capabilitiesNotified" , this . onWidgetCapabilitiesNotified ) ;
315+ this . sgWidget ? .on ( "capabilitiesNotified" , this . onWidgetCapabilitiesNotified ) ;
316316 }
317317
318318 private stopSgListeners ( ) : void {
@@ -336,7 +336,7 @@ export default class AppTile extends React.Component<IProps, IState> {
336336 }
337337
338338 private startWidget ( ) : void {
339- this . sgWidget . prepare ( ) . then ( ( ) => {
339+ this . sgWidget ? .prepare ( ) . then ( ( ) => {
340340 if ( this . unmounted ) return ;
341341 this . setState ( { initialising : false } ) ;
342342 } ) ;
@@ -406,7 +406,7 @@ export default class AppTile extends React.Component<IProps, IState> {
406406
407407 private onWidgetCapabilitiesNotified = ( ) : void => {
408408 this . setState ( {
409- requiresClient : this . sgWidget . widgetApi . hasCapability ( ElementWidgetCapabilities . RequiresClient ) ,
409+ requiresClient : ! ! this . sgWidget ? .widgetApi ? .hasCapability ( ElementWidgetCapabilities . RequiresClient ) ,
410410 } ) ;
411411 } ;
412412
@@ -415,7 +415,7 @@ export default class AppTile extends React.Component<IProps, IState> {
415415 case "m.sticker" :
416416 if (
417417 payload . widgetId === this . props . app . id &&
418- this . sgWidget . widgetApi . hasCapability ( MatrixCapabilities . StickerSending )
418+ this . sgWidget ? .widgetApi ? .hasCapability ( MatrixCapabilities . StickerSending )
419419 ) {
420420 dis . dispatch ( {
421421 action : "post_sticker_message" ,
@@ -444,8 +444,8 @@ export default class AppTile extends React.Component<IProps, IState> {
444444 logger . info ( "Granting permission for widget to load: " + this . props . app . eventId ) ;
445445 const current = SettingsStore . getValue ( "allowedWidgets" , roomId ) ;
446446 if ( this . props . app . eventId !== undefined ) current [ this . props . app . eventId ] = true ;
447- const level = SettingsStore . firstSupportedLevel ( "allowedWidgets" ) ;
448- SettingsStore . setValue ( "allowedWidgets" , roomId , level , current )
447+ const level = SettingsStore . firstSupportedLevel ( "allowedWidgets" ) ! ;
448+ SettingsStore . setValue ( "allowedWidgets" , roomId ?? null , level , current )
449449 . then ( ( ) => {
450450 this . setState ( { hasPermissionToLoad : true } ) ;
451451
@@ -501,7 +501,7 @@ export default class AppTile extends React.Component<IProps, IState> {
501501 this . resetWidget ( this . props ) ;
502502 this . startMessaging ( ) ;
503503
504- if ( this . iframe ) {
504+ if ( this . iframe && this . sgWidget ) {
505505 // Reload iframe
506506 this . iframe . src = this . sgWidget . embedUrl ;
507507 }
@@ -519,7 +519,7 @@ export default class AppTile extends React.Component<IProps, IState> {
519519 // window.open(this._getPopoutUrl(), '_blank', 'noopener=yes');
520520 Object . assign ( document . createElement ( "a" ) , {
521521 target : "_blank" ,
522- href : this . sgWidget . popoutUrl ,
522+ href : this . sgWidget ? .popoutUrl ,
523523 rel : "noreferrer noopener" ,
524524 } ) . click ( ) ;
525525 } ;
@@ -676,7 +676,7 @@ export default class AppTile extends React.Component<IProps, IState> {
676676 if ( this . state . menuDisplayed ) {
677677 contextMenu = (
678678 < WidgetContextMenu
679- { ...aboveLeftOf ( this . contextMenuButton . current . getBoundingClientRect ( ) , null ) }
679+ { ...aboveLeftOf ( this . contextMenuButton . current . getBoundingClientRect ( ) ) }
680680 app = { this . props . app }
681681 onFinished = { this . closeContextMenu }
682682 showUnpin = { ! this . props . userWidget }
0 commit comments