@@ -25,6 +25,12 @@ 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 RightPanelStore from '../../../stores/RightPanelStore' ;
30
+ import { RightPanelPhases } from '../../../stores/RightPanelStorePhases' ;
31
+ import dis from '../../../dispatcher/dispatcher' ;
32
+ import { ActionPayload } from '../../../dispatcher/payloads' ;
33
+ import { Action } from '../../../dispatcher/actions' ;
28
34
29
35
interface IProps {
30
36
// none
@@ -33,22 +39,25 @@ interface IProps {
33
39
interface IState {
34
40
roomId : string ;
35
41
persistentWidgetId : string ;
42
+ rightPanelPhase ?: RightPanelPhases ;
36
43
}
37
44
38
45
@replaceableComponent ( "views.elements.PersistentApp" )
39
46
export default class PersistentApp extends React . Component < IProps , IState > {
40
47
private roomStoreToken : EventSubscription ;
41
-
48
+ private dispatcherRef : string ;
42
49
constructor ( props : IProps ) {
43
50
super ( props ) ;
44
51
45
52
this . state = {
46
53
roomId : RoomViewStore . getRoomId ( ) ,
47
54
persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
55
+ rightPanelPhase : RightPanelStore . getSharedInstance ( ) . roomPanelPhase ,
48
56
} ;
49
57
}
50
58
51
59
public componentDidMount ( ) : void {
60
+ this . dispatcherRef = dis . register ( this . onWidgetAction ) ;
52
61
this . roomStoreToken = RoomViewStore . addListener ( this . onRoomViewStoreUpdate ) ;
53
62
ActiveWidgetStore . instance . on ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
54
63
MatrixClientPeg . get ( ) . on ( "Room.myMembership" , this . onMyMembership ) ;
@@ -58,6 +67,9 @@ export default class PersistentApp extends React.Component<IProps, IState> {
58
67
if ( this . roomStoreToken ) {
59
68
this . roomStoreToken . remove ( ) ;
60
69
}
70
+ if ( this . dispatcherRef ) {
71
+ dis . unregister ( this . dispatcherRef ) ;
72
+ }
61
73
ActiveWidgetStore . instance . removeListener ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
62
74
if ( MatrixClientPeg . get ( ) ) {
63
75
MatrixClientPeg . get ( ) . removeListener ( "Room.myMembership" , this . onMyMembership ) ;
@@ -71,6 +83,17 @@ export default class PersistentApp extends React.Component<IProps, IState> {
71
83
} ) ;
72
84
} ;
73
85
86
+ private onWidgetAction = ( payload : ActionPayload ) : void => {
87
+ switch ( payload . action ) {
88
+ case Action . AfterRightPanelPhaseChange :
89
+ this . setState ( {
90
+ rightPanelPhase : RightPanelStore . getSharedInstance ( ) . roomPanelPhase ,
91
+ } ) ;
92
+ break ;
93
+ default : break ;
94
+ }
95
+ } ;
96
+
74
97
private onActiveWidgetStoreUpdate = ( ) : void => {
75
98
this . setState ( {
76
99
persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
@@ -88,17 +111,34 @@ export default class PersistentApp extends React.Component<IProps, IState> {
88
111
} ;
89
112
90
113
public render ( ) : JSX . Element {
91
- if ( this . state . persistentWidgetId ) {
92
- const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( this . state . persistentWidgetId ) ;
114
+ const wId = this . state . persistentWidgetId ;
115
+ if ( wId ) {
116
+ const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( wId ) ;
93
117
94
118
const persistentWidgetInRoom = MatrixClientPeg . get ( ) . getRoom ( persistentWidgetInRoomId ) ;
95
119
96
120
// Sanity check the room - the widget may have been destroyed between render cycles, and
97
121
// thus no room is associated anymore.
98
122
if ( ! persistentWidgetInRoom ) return null ;
99
123
100
- const myMembership = persistentWidgetInRoom . getMyMembership ( ) ;
101
- if ( this . state . roomId !== persistentWidgetInRoomId && myMembership === "join" ) {
124
+ const wls = WidgetLayoutStore . instance ;
125
+
126
+ const userIsPartOfTheRoom = persistentWidgetInRoom . getMyMembership ( ) == "join" ;
127
+ const fromAnotherRoom = this . state . roomId !== persistentWidgetInRoomId ;
128
+
129
+ const notInRightPanel =
130
+ ! ( this . state . rightPanelPhase == RightPanelPhases . Widget &&
131
+ wId == RightPanelStore . getSharedInstance ( ) . roomPanelPhaseParams ?. widgetId ) ;
132
+ const notInCenterContainer =
133
+ ! wls . getContainerWidgets ( persistentWidgetInRoom , Container . Center )
134
+ . find ( ( app ) => app . id == wId ) ;
135
+ const notInTopContainer =
136
+ ! wls . getContainerWidgets ( persistentWidgetInRoom , Container . Top ) . find ( app => app . id == wId ) ;
137
+ if (
138
+ //Show the persistent widget in two cases. The booleans have to be read like this: the widget is-`fromAnotherRoom`:
139
+ ( fromAnotherRoom && userIsPartOfTheRoom ) ||
140
+ ( notInRightPanel && notInCenterContainer && notInTopContainer && userIsPartOfTheRoom )
141
+ ) {
102
142
// get the widget data
103
143
const appEvent = WidgetUtils . getRoomWidgets ( persistentWidgetInRoom ) . find ( ( ev ) => {
104
144
return ev . getStateKey ( ) === ActiveWidgetStore . instance . getPersistentWidgetId ( ) ;
0 commit comments