@@ -25,6 +25,12 @@ 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 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' ;
2834
2935interface IProps {
3036 // none
@@ -33,22 +39,25 @@ interface IProps {
3339interface IState {
3440 roomId : string ;
3541 persistentWidgetId : string ;
42+ rightPanelPhase ?: RightPanelPhases ;
3643}
3744
3845@replaceableComponent ( "views.elements.PersistentApp" )
3946export default class PersistentApp extends React . Component < IProps , IState > {
4047 private roomStoreToken : EventSubscription ;
41-
48+ private dispatcherRef : string ;
4249 constructor ( props : IProps ) {
4350 super ( props ) ;
4451
4552 this . state = {
4653 roomId : RoomViewStore . getRoomId ( ) ,
4754 persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
55+ rightPanelPhase : RightPanelStore . getSharedInstance ( ) . roomPanelPhase ,
4856 } ;
4957 }
5058
5159 public componentDidMount ( ) : void {
60+ this . dispatcherRef = dis . register ( this . onWidgetAction ) ;
5261 this . roomStoreToken = RoomViewStore . addListener ( this . onRoomViewStoreUpdate ) ;
5362 ActiveWidgetStore . instance . on ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
5463 MatrixClientPeg . get ( ) . on ( "Room.myMembership" , this . onMyMembership ) ;
@@ -58,6 +67,9 @@ export default class PersistentApp extends React.Component<IProps, IState> {
5867 if ( this . roomStoreToken ) {
5968 this . roomStoreToken . remove ( ) ;
6069 }
70+ if ( this . dispatcherRef ) {
71+ dis . unregister ( this . dispatcherRef ) ;
72+ }
6173 ActiveWidgetStore . instance . removeListener ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
6274 if ( MatrixClientPeg . get ( ) ) {
6375 MatrixClientPeg . get ( ) . removeListener ( "Room.myMembership" , this . onMyMembership ) ;
@@ -71,6 +83,17 @@ export default class PersistentApp extends React.Component<IProps, IState> {
7183 } ) ;
7284 } ;
7385
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+
7497 private onActiveWidgetStoreUpdate = ( ) : void => {
7598 this . setState ( {
7699 persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
@@ -88,17 +111,34 @@ export default class PersistentApp extends React.Component<IProps, IState> {
88111 } ;
89112
90113 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 ) ;
93117
94118 const persistentWidgetInRoom = MatrixClientPeg . get ( ) . getRoom ( persistentWidgetInRoomId ) ;
95119
96120 // Sanity check the room - the widget may have been destroyed between render cycles, and
97121 // thus no room is associated anymore.
98122 if ( ! persistentWidgetInRoom ) return null ;
99123
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+ ) {
102142 // get the widget data
103143 const appEvent = WidgetUtils . getRoomWidgets ( persistentWidgetInRoom ) . find ( ( ev ) => {
104144 return ev . getStateKey ( ) === ActiveWidgetStore . instance . getPersistentWidgetId ( ) ;
0 commit comments