@@ -199,10 +199,7 @@ export default class PipView extends React.Component<IProps, IState> {
199
199
} ;
200
200
201
201
private onActiveWidgetStoreUpdate = ( ) : void => {
202
- this . setState ( {
203
- persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
204
- } ) ;
205
- this . updateShowWidgetInPip ( ) ;
202
+ this . updateShowWidgetInPip ( ActiveWidgetStore . instance . getPersistentWidgetId ( ) ) ;
206
203
} ;
207
204
208
205
private updateCalls = ( ) : void => {
@@ -237,24 +234,23 @@ export default class PipView extends React.Component<IProps, IState> {
237
234
}
238
235
} ;
239
236
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 ) {
243
239
let userIsPartOfTheRoom = false ;
244
240
let fromAnotherRoom = false ;
245
241
let notVisible = false ;
246
- if ( wId ) {
247
- const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( wId ) ;
242
+ if ( persistentWidgetId ) {
243
+ const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( persistentWidgetId ) ;
248
244
const persistentWidgetInRoom = MatrixClientPeg . get ( ) . getRoom ( persistentWidgetInRoomId ) ;
249
245
250
246
// Sanity check the room - the widget may have been destroyed between render cycles, and
251
247
// 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
+ }
258
254
}
259
255
260
256
// 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> {
263
259
( fromAnotherRoom && userIsPartOfTheRoom ) ||
264
260
( notVisible && userIsPartOfTheRoom ) ;
265
261
266
- this . setState ( { showWidgetInPip } ) ;
262
+ this . setState ( { showWidgetInPip, persistentWidgetId } ) ;
267
263
}
268
264
269
265
public render ( ) {
0 commit comments