@@ -25,6 +25,10 @@ import WidgetUtils from '../../../utils/WidgetUtils';
25
25
import { MatrixClientPeg } from '../../../MatrixClientPeg' ;
26
26
import { replaceableComponent } from "../../../utils/replaceableComponent" ;
27
27
import 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' ;
28
32
29
33
interface IProps {
30
34
// none
@@ -33,6 +37,7 @@ interface IProps {
33
37
interface IState {
34
38
roomId : string ;
35
39
persistentWidgetId : string ;
40
+ rightPanelPhase ?: RightPanelPhases ;
36
41
}
37
42
38
43
@replaceableComponent ( "views.elements.PersistentApp" )
@@ -45,12 +50,14 @@ export default class PersistentApp extends React.Component<IProps, IState> {
45
50
this . state = {
46
51
roomId : RoomViewStore . getRoomId ( ) ,
47
52
persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
53
+ rightPanelPhase : RightPanelStore . instance . currentCard . phase ,
48
54
} ;
49
55
}
50
56
51
57
public componentDidMount ( ) : void {
52
58
this . roomStoreToken = RoomViewStore . addListener ( this . onRoomViewStoreUpdate ) ;
53
59
ActiveWidgetStore . instance . on ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
60
+ RightPanelStore . instance . on ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
54
61
MatrixClientPeg . get ( ) . on ( "Room.myMembership" , this . onMyMembership ) ;
55
62
}
56
63
@@ -59,6 +66,7 @@ export default class PersistentApp extends React.Component<IProps, IState> {
59
66
this . roomStoreToken . remove ( ) ;
60
67
}
61
68
ActiveWidgetStore . instance . removeListener ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
69
+ RightPanelStore . instance . off ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
62
70
if ( MatrixClientPeg . get ( ) ) {
63
71
MatrixClientPeg . get ( ) . removeListener ( "Room.myMembership" , this . onMyMembership ) ;
64
72
}
@@ -71,6 +79,12 @@ export default class PersistentApp extends React.Component<IProps, IState> {
71
79
} ) ;
72
80
} ;
73
81
82
+ private onRightPanelStoreUpdate = ( ) => {
83
+ this . setState ( {
84
+ rightPanelPhase : RightPanelStore . instance . currentCard . phase ,
85
+ } ) ;
86
+ } ;
87
+
74
88
private onActiveWidgetStoreUpdate = ( ) : void => {
75
89
this . setState ( {
76
90
persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
@@ -88,17 +102,34 @@ export default class PersistentApp extends React.Component<IProps, IState> {
88
102
} ;
89
103
90
104
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 ) ;
93
108
94
109
const persistentWidgetInRoom = MatrixClientPeg . get ( ) . getRoom ( persistentWidgetInRoomId ) ;
95
110
96
111
// Sanity check the room - the widget may have been destroyed between render cycles, and
97
112
// thus no room is associated anymore.
98
113
if ( ! persistentWidgetInRoom ) return null ;
99
114
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
+ ) {
102
133
// get the widget data
103
134
const appEvent = WidgetUtils . getRoomWidgets ( persistentWidgetInRoom ) . find ( ( ev ) => {
104
135
return ev . getStateKey ( ) === ActiveWidgetStore . instance . getPersistentWidgetId ( ) ;
0 commit comments