@@ -25,6 +25,10 @@ import WidgetUtils from '../../../utils/WidgetUtils';
2525import { MatrixClientPeg } from '../../../MatrixClientPeg' ;
2626import { replaceableComponent } from "../../../utils/replaceableComponent" ;
2727import AppTile from "./AppTile" ;
28+ import { Container , WidgetLayoutStore } from '../../../stores/widgets/WidgetLayoutStore' ;
29+ import { RightPanelPhases } from '../../../stores/right-panel/RightPanelStorePhases' ;
30+ import RightPanelStore from '../../../stores/right-panel/RightPanelStore' ;
31+ import { UPDATE_EVENT } from '../../../stores/AsyncStore' ;
2832
2933interface IProps {
3034 // none
@@ -33,6 +37,7 @@ interface IProps {
3337interface IState {
3438 roomId : string ;
3539 persistentWidgetId : string ;
40+ rightPanelPhase ?: RightPanelPhases ;
3641}
3742
3843@replaceableComponent ( "views.elements.PersistentApp" )
@@ -45,12 +50,14 @@ export default class PersistentApp extends React.Component<IProps, IState> {
4550 this . state = {
4651 roomId : RoomViewStore . getRoomId ( ) ,
4752 persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
53+ rightPanelPhase : RightPanelStore . instance . currentCard . phase ,
4854 } ;
4955 }
5056
5157 public componentDidMount ( ) : void {
5258 this . roomStoreToken = RoomViewStore . addListener ( this . onRoomViewStoreUpdate ) ;
5359 ActiveWidgetStore . instance . on ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
60+ RightPanelStore . instance . on ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
5461 MatrixClientPeg . get ( ) . on ( "Room.myMembership" , this . onMyMembership ) ;
5562 }
5663
@@ -59,6 +66,7 @@ export default class PersistentApp extends React.Component<IProps, IState> {
5966 this . roomStoreToken . remove ( ) ;
6067 }
6168 ActiveWidgetStore . instance . removeListener ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
69+ RightPanelStore . instance . off ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
6270 if ( MatrixClientPeg . get ( ) ) {
6371 MatrixClientPeg . get ( ) . removeListener ( "Room.myMembership" , this . onMyMembership ) ;
6472 }
@@ -71,6 +79,12 @@ export default class PersistentApp extends React.Component<IProps, IState> {
7179 } ) ;
7280 } ;
7381
82+ private onRightPanelStoreUpdate = ( ) => {
83+ this . setState ( {
84+ rightPanelPhase : RightPanelStore . instance . currentCard . phase ,
85+ } ) ;
86+ } ;
87+
7488 private onActiveWidgetStoreUpdate = ( ) : void => {
7589 this . setState ( {
7690 persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
@@ -88,17 +102,34 @@ export default class PersistentApp extends React.Component<IProps, IState> {
88102 } ;
89103
90104 public render ( ) : JSX . Element {
91- if ( this . state . persistentWidgetId ) {
92- const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( this . state . persistentWidgetId ) ;
105+ const wId = this . state . persistentWidgetId ;
106+ if ( wId ) {
107+ const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( wId ) ;
93108
94109 const persistentWidgetInRoom = MatrixClientPeg . get ( ) . getRoom ( persistentWidgetInRoomId ) ;
95110
96111 // Sanity check the room - the widget may have been destroyed between render cycles, and
97112 // thus no room is associated anymore.
98113 if ( ! persistentWidgetInRoom ) return null ;
99114
100- const myMembership = persistentWidgetInRoom . getMyMembership ( ) ;
101- if ( this . state . roomId !== persistentWidgetInRoomId && myMembership === "join" ) {
115+ const wls = WidgetLayoutStore . instance ;
116+
117+ const userIsPartOfTheRoom = persistentWidgetInRoom . getMyMembership ( ) == "join" ;
118+ const fromAnotherRoom = this . state . roomId !== persistentWidgetInRoomId ;
119+
120+ const notInRightPanel =
121+ ! ( this . state . rightPanelPhase == RightPanelPhases . Widget &&
122+ wId == RightPanelStore . instance . currentCard . state ?. widgetId ) ;
123+ const notInCenterContainer =
124+ ! wls . getContainerWidgets ( persistentWidgetInRoom , Container . Center ) . some ( ( app ) => app . id == wId ) ;
125+ const notInTopContainer =
126+ ! wls . getContainerWidgets ( persistentWidgetInRoom , Container . Top ) . some ( app => app . id == wId ) ;
127+ if (
128+ // the widget should only be shown as a persistent app (in a floating pip container) if it is not visible on screen
129+ // either, because we are viewing a different room OR because it is in none of the possible containers of the room view.
130+ ( fromAnotherRoom && userIsPartOfTheRoom ) ||
131+ ( notInRightPanel && notInCenterContainer && notInTopContainer && userIsPartOfTheRoom )
132+ ) {
102133 // get the widget data
103134 const appEvent = WidgetUtils . getRoomWidgets ( persistentWidgetInRoom ) . find ( ( ev ) => {
104135 return ev . getStateKey ( ) === ActiveWidgetStore . instance . getPersistentWidgetId ( ) ;
0 commit comments