@@ -118,24 +118,27 @@ export default class AppTile extends React.Component<IProps, IState> {
118118 showLayoutButtons : true ,
119119 } ;
120120
121- // We track a count of all "live" `AppTile`s for a given widget ID .
121+ // We track a count of all "live" `AppTile`s for a given widget UID .
122122 // For this purpose, an `AppTile` is considered live from the time it is
123123 // constructed until it is unmounted. This is used to aid logic around when
124124 // to tear down the widget iframe. See `componentWillUnmount` for details.
125- private static liveTilesById : { [ key : string ] : number } = { } ;
125+ private static liveTilesByUid = new Map < string , number > ( ) ;
126126
127- public static addLiveTile ( widgetId : string ) : void {
128- const refs = this . liveTilesById [ widgetId ] || 0 ;
129- this . liveTilesById [ widgetId ] = refs + 1 ;
127+ public static addLiveTile ( widgetId : string , roomId : string ) : void {
128+ const uid = WidgetUtils . calcWidgetUid ( widgetId , roomId ) ;
129+ const refs = this . liveTilesByUid . get ( uid ) ?? 0 ;
130+ this . liveTilesByUid . set ( uid , refs + 1 ) ;
130131 }
131132
132- public static removeLiveTile ( widgetId : string ) : void {
133- const refs = this . liveTilesById [ widgetId ] || 0 ;
134- this . liveTilesById [ widgetId ] = refs - 1 ;
133+ public static removeLiveTile ( widgetId : string , roomId : string ) : void {
134+ const uid = WidgetUtils . calcWidgetUid ( widgetId , roomId ) ;
135+ const refs = this . liveTilesByUid . get ( uid ) ;
136+ if ( refs ) this . liveTilesByUid . set ( uid , refs - 1 ) ;
135137 }
136138
137- public static isLive ( widgetId : string ) : boolean {
138- const refs = this . liveTilesById [ widgetId ] || 0 ;
139+ public static isLive ( widgetId : string , roomId : string ) : boolean {
140+ const uid = WidgetUtils . calcWidgetUid ( widgetId , roomId ) ;
141+ const refs = this . liveTilesByUid . get ( uid ) ?? 0 ;
139142 return refs > 0 ;
140143 }
141144
@@ -150,10 +153,10 @@ export default class AppTile extends React.Component<IProps, IState> {
150153 constructor ( props : IProps ) {
151154 super ( props ) ;
152155
153- AppTile . addLiveTile ( this . props . app . id ) ;
156+ AppTile . addLiveTile ( this . props . app . id , this . props . app . roomId ) ;
154157
155158 // The key used for PersistedElement
156- this . persistKey = getPersistKey ( this . props . app . id ) ;
159+ this . persistKey = getPersistKey ( WidgetUtils . getWidgetUid ( this . props . app ) ) ;
157160 try {
158161 this . sgWidget = new StopGapWidget ( this . props ) ;
159162 this . setupSgListeners ( ) ;
@@ -189,7 +192,9 @@ export default class AppTile extends React.Component<IProps, IState> {
189192 } ;
190193
191194 private onUserLeftRoom ( ) {
192- const isActiveWidget = ActiveWidgetStore . instance . getWidgetPersistence ( this . props . app . id ) ;
195+ const isActiveWidget = ActiveWidgetStore . instance . getWidgetPersistence (
196+ this . props . app . id , this . props . app . roomId ,
197+ ) ;
193198 if ( isActiveWidget ) {
194199 // We just left the room that the active widget was from.
195200 if ( this . props . room && RoomViewStore . getRoomId ( ) !== this . props . room . roomId ) {
@@ -200,7 +205,7 @@ export default class AppTile extends React.Component<IProps, IState> {
200205 this . reload ( ) ;
201206 } else {
202207 // Otherwise just cancel its persistence.
203- ActiveWidgetStore . instance . destroyPersistentWidget ( this . props . app . id ) ;
208+ ActiveWidgetStore . instance . destroyPersistentWidget ( this . props . app . id , this . props . app . roomId ) ;
204209 }
205210 }
206211 }
@@ -241,7 +246,7 @@ export default class AppTile extends React.Component<IProps, IState> {
241246
242247 if ( this . state . hasPermissionToLoad && ! hasPermissionToLoad ) {
243248 // Force the widget to be non-persistent (able to be deleted/forgotten)
244- ActiveWidgetStore . instance . destroyPersistentWidget ( this . props . app . id ) ;
249+ ActiveWidgetStore . instance . destroyPersistentWidget ( this . props . app . id , this . props . app . roomId ) ;
245250 PersistedElement . destroyElement ( this . persistKey ) ;
246251 this . sgWidget ?. stopMessaging ( ) ;
247252 }
@@ -291,14 +296,16 @@ export default class AppTile extends React.Component<IProps, IState> {
291296 // container is constructed before the old one unmounts. By counting the
292297 // mounted `AppTile`s for each widget, we know to only tear down the
293298 // widget iframe when the last the `AppTile` unmounts.
294- AppTile . removeLiveTile ( this . props . app . id ) ;
299+ AppTile . removeLiveTile ( this . props . app . id , this . props . app . roomId ) ;
295300
296301 // We also support a separate "persistence" mode where a single widget
297302 // can request to be "sticky" and follow you across rooms in a PIP
298303 // container.
299- const isActiveWidget = ActiveWidgetStore . instance . getWidgetPersistence ( this . props . app . id ) ;
304+ const isActiveWidget = ActiveWidgetStore . instance . getWidgetPersistence (
305+ this . props . app . id , this . props . app . roomId ,
306+ ) ;
300307
301- if ( ! AppTile . isLive ( this . props . app . id ) && ! isActiveWidget ) {
308+ if ( ! AppTile . isLive ( this . props . app . id , this . props . app . roomId ) && ! isActiveWidget ) {
302309 this . endWidgetActions ( ) ;
303310 }
304311
@@ -408,7 +415,7 @@ export default class AppTile extends React.Component<IProps, IState> {
408415
409416 // Delete the widget from the persisted store for good measure.
410417 PersistedElement . destroyElement ( this . persistKey ) ;
411- ActiveWidgetStore . instance . destroyPersistentWidget ( this . props . app . id ) ;
418+ ActiveWidgetStore . instance . destroyPersistentWidget ( this . props . app . id , this . props . app . roomId ) ;
412419
413420 this . sgWidget ?. stopMessaging ( { forceDestroy : true } ) ;
414421 }
0 commit comments