@@ -199,10 +199,7 @@ export default class PipView extends React.Component<IProps, IState> {
199199 } ;
200200
201201 private onActiveWidgetStoreUpdate = ( ) : void => {
202- this . setState ( {
203- persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
204- } ) ;
205- this . updateShowWidgetInPip ( ) ;
202+ this . updateShowWidgetInPip ( ActiveWidgetStore . instance . getPersistentWidgetId ( ) ) ;
206203 } ;
207204
208205 private updateCalls = ( ) : void => {
@@ -237,24 +234,23 @@ export default class PipView extends React.Component<IProps, IState> {
237234 }
238235 } ;
239236
240- public updateShowWidgetInPip ( ) {
241- const wId = this . state . persistentWidgetId ;
242-
237+ // Accepts a persistentWidgetId to be able to skip awaiting the setState for persistentWidgetId
238+ public updateShowWidgetInPip ( persistentWidgetId = this . state . persistentWidgetId ) {
243239 let userIsPartOfTheRoom = false ;
244240 let fromAnotherRoom = false ;
245241 let notVisible = false ;
246- if ( wId ) {
247- const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( wId ) ;
242+ if ( persistentWidgetId ) {
243+ const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( persistentWidgetId ) ;
248244 const persistentWidgetInRoom = MatrixClientPeg . get ( ) . getRoom ( persistentWidgetInRoomId ) ;
249245
250246 // Sanity check the room - the widget may have been destroyed between render cycles, and
251247 // thus no room is associated anymore.
252- if ( ! persistentWidgetInRoom ) return null ;
253-
254- const wls = WidgetLayoutStore . instance ;
255- notVisible = ! wls . isVisibleOnScreen ( persistentWidgetInRoom , wId ) ;
256- userIsPartOfTheRoom = persistentWidgetInRoom . getMyMembership ( ) == "join" ;
257- fromAnotherRoom = this . state . viewedRoomId !== persistentWidgetInRoomId ;
248+ if ( persistentWidgetInRoom ) {
249+ const wls = WidgetLayoutStore . instance ;
250+ notVisible = ! wls . isVisibleOnScreen ( persistentWidgetInRoom , persistentWidgetId ) ;
251+ userIsPartOfTheRoom = persistentWidgetInRoom . getMyMembership ( ) == "join" ;
252+ fromAnotherRoom = this . state . viewedRoomId ! == persistentWidgetInRoomId ;
253+ }
258254 }
259255
260256 // The widget should only be shown as a persistent app (in a floating pip container) if it is not visible on screen
@@ -263,7 +259,7 @@ export default class PipView extends React.Component<IProps, IState> {
263259 ( fromAnotherRoom && userIsPartOfTheRoom ) ||
264260 ( notVisible && userIsPartOfTheRoom ) ;
265261
266- this . setState ( { showWidgetInPip } ) ;
262+ this . setState ( { showWidgetInPip, persistentWidgetId } ) ;
267263 }
268264
269265 public render ( ) {
0 commit comments