@@ -16,141 +16,79 @@ limitations under the License.
16
16
*/
17
17
18
18
import React from 'react' ;
19
- import { EventSubscription } from 'fbemitter' ;
20
19
import { Room } from "matrix-js-sdk/src/models/room" ;
21
20
22
21
import RoomViewStore from '../../../stores/RoomViewStore' ;
23
- import ActiveWidgetStore , { ActiveWidgetStoreEvent } from '../../../stores/ActiveWidgetStore' ;
22
+ import ActiveWidgetStore from '../../../stores/ActiveWidgetStore' ;
24
23
import WidgetUtils from '../../../utils/WidgetUtils' ;
25
24
import { MatrixClientPeg } from '../../../MatrixClientPeg' ;
26
25
import { replaceableComponent } from "../../../utils/replaceableComponent" ;
27
26
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' ;
32
27
33
28
interface IProps {
34
- // none
29
+ persistentWidgetId : string ;
30
+ pointerEvents ?: string ;
35
31
}
36
32
37
33
interface IState {
38
34
roomId : string ;
39
- persistentWidgetId : string ;
40
- rightPanelPhase ?: RightPanelPhases ;
41
35
}
42
36
43
37
@replaceableComponent ( "views.elements.PersistentApp" )
44
38
export default class PersistentApp extends React . Component < IProps , IState > {
45
- private roomStoreToken : EventSubscription ;
46
-
47
39
constructor ( props : IProps ) {
48
40
super ( props ) ;
49
41
50
42
this . state = {
51
43
roomId : RoomViewStore . getRoomId ( ) ,
52
- persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
53
- rightPanelPhase : RightPanelStore . instance . currentCard . phase ,
54
44
} ;
55
45
}
56
46
57
47
public componentDidMount ( ) : void {
58
- this . roomStoreToken = RoomViewStore . addListener ( this . onRoomViewStoreUpdate ) ;
59
- ActiveWidgetStore . instance . on ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
60
- RightPanelStore . instance . on ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
61
48
MatrixClientPeg . get ( ) . on ( "Room.myMembership" , this . onMyMembership ) ;
62
49
}
63
50
64
51
public componentWillUnmount ( ) : void {
65
- if ( this . roomStoreToken ) {
66
- this . roomStoreToken . remove ( ) ;
67
- }
68
- ActiveWidgetStore . instance . removeListener ( ActiveWidgetStoreEvent . Update , this . onActiveWidgetStoreUpdate ) ;
69
- RightPanelStore . instance . off ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
70
- if ( MatrixClientPeg . get ( ) ) {
71
- MatrixClientPeg . get ( ) . removeListener ( "Room.myMembership" , this . onMyMembership ) ;
72
- }
52
+ MatrixClientPeg . get ( ) . off ( "Room.myMembership" , this . onMyMembership ) ;
73
53
}
74
54
75
- private onRoomViewStoreUpdate = ( ) : void => {
76
- if ( RoomViewStore . getRoomId ( ) === this . state . roomId ) return ;
77
- this . setState ( {
78
- roomId : RoomViewStore . getRoomId ( ) ,
79
- } ) ;
80
- } ;
81
-
82
- private onRightPanelStoreUpdate = ( ) => {
83
- this . setState ( {
84
- rightPanelPhase : RightPanelStore . instance . currentCard . phase ,
85
- } ) ;
86
- } ;
87
-
88
- private onActiveWidgetStoreUpdate = ( ) : void => {
89
- this . setState ( {
90
- persistentWidgetId : ActiveWidgetStore . instance . getPersistentWidgetId ( ) ,
91
- } ) ;
92
- } ;
93
-
94
55
private onMyMembership = async ( room : Room , membership : string ) : Promise < void > => {
95
- const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( this . state . persistentWidgetId ) ;
56
+ const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( this . props . persistentWidgetId ) ;
96
57
if ( membership !== "join" ) {
97
58
// we're not in the room anymore - delete
98
- if ( room . roomId === persistentWidgetInRoomId ) {
99
- ActiveWidgetStore . instance . destroyPersistentWidget ( this . state . persistentWidgetId ) ;
59
+ if ( room . roomId === persistentWidgetInRoomId ) {
60
+ ActiveWidgetStore . instance . destroyPersistentWidget ( this . props . persistentWidgetId ) ;
100
61
}
101
62
}
102
63
} ;
103
64
104
65
public render ( ) : JSX . Element {
105
- const wId = this . state . persistentWidgetId ;
66
+ const wId = this . props . persistentWidgetId ;
106
67
if ( wId ) {
107
68
const persistentWidgetInRoomId = ActiveWidgetStore . instance . getRoomId ( wId ) ;
108
-
109
69
const persistentWidgetInRoom = MatrixClientPeg . get ( ) . getRoom ( persistentWidgetInRoomId ) ;
110
70
111
- // Sanity check the room - the widget may have been destroyed between render cycles, and
112
- // thus no room is associated anymore.
113
- if ( ! persistentWidgetInRoom ) return null ;
114
-
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
- ) {
133
- // get the widget data
134
- const appEvent = WidgetUtils . getRoomWidgets ( persistentWidgetInRoom ) . find ( ( ev ) => {
135
- return ev . getStateKey ( ) === ActiveWidgetStore . instance . getPersistentWidgetId ( ) ;
136
- } ) ;
137
- const app = WidgetUtils . makeAppConfig (
138
- appEvent . getStateKey ( ) , appEvent . getContent ( ) , appEvent . getSender ( ) ,
139
- persistentWidgetInRoomId , appEvent . getId ( ) ,
140
- ) ;
141
- return < AppTile
142
- key = { app . id }
143
- app = { app }
144
- fullWidth = { true }
145
- room = { persistentWidgetInRoom }
146
- userId = { MatrixClientPeg . get ( ) . credentials . userId }
147
- creatorUserId = { app . creatorUserId }
148
- widgetPageTitle = { WidgetUtils . getWidgetDataTitle ( app ) }
149
- waitForIframeLoad = { app . waitForIframeLoad }
150
- miniMode = { true }
151
- showMenubar = { false }
152
- /> ;
153
- }
71
+ // get the widget data
72
+ const appEvent = WidgetUtils . getRoomWidgets ( persistentWidgetInRoom ) . find ( ( ev ) => {
73
+ return ev . getStateKey ( ) === ActiveWidgetStore . instance . getPersistentWidgetId ( ) ;
74
+ } ) ;
75
+ const app = WidgetUtils . makeAppConfig (
76
+ appEvent . getStateKey ( ) , appEvent . getContent ( ) , appEvent . getSender ( ) ,
77
+ persistentWidgetInRoomId , appEvent . getId ( ) ,
78
+ ) ;
79
+ return < AppTile
80
+ key = { app . id }
81
+ app = { app }
82
+ fullWidth = { true }
83
+ room = { persistentWidgetInRoom }
84
+ userId = { MatrixClientPeg . get ( ) . credentials . userId }
85
+ creatorUserId = { app . creatorUserId }
86
+ widgetPageTitle = { WidgetUtils . getWidgetDataTitle ( app ) }
87
+ waitForIframeLoad = { app . waitForIframeLoad }
88
+ miniMode = { true }
89
+ showMenubar = { false }
90
+ pointerEvents = { this . props . pointerEvents }
91
+ /> ;
154
92
}
155
93
return null ;
156
94
}
0 commit comments