mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-16 05:51:33 +03:00
88 lines
3.3 KiB
JavaScript
88 lines
3.3 KiB
JavaScript
|
/*
|
||
|
Copyright 2018 New Vector Ltd
|
||
|
|
||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
|
|
||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License.
|
||
|
*/
|
||
|
|
||
|
import React from 'react';
|
||
|
import RoomViewStore from '../../../stores/RoomViewStore';
|
||
|
import ActiveWidgetStore from '../../../stores/ActiveWidgetStore';
|
||
|
import WidgetUtils from '../../../utils/WidgetUtils';
|
||
|
import sdk from '../../../index';
|
||
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||
|
|
||
|
module.exports = React.createClass({
|
||
|
displayName: 'PersistentApp',
|
||
|
|
||
|
getInitialState: function() {
|
||
|
return {
|
||
|
roomId: RoomViewStore.getRoomId(),
|
||
|
};
|
||
|
},
|
||
|
|
||
|
componentWillMount: function() {
|
||
|
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
||
|
},
|
||
|
|
||
|
componentWillUnmount: function() {
|
||
|
if (this._roomStoreToken) {
|
||
|
this._roomStoreToken.remove();
|
||
|
}
|
||
|
},
|
||
|
|
||
|
_onRoomViewStoreUpdate: function(payload) {
|
||
|
if (RoomViewStore.getRoomId() === this.state.roomId) return;
|
||
|
this.setState({
|
||
|
roomId: RoomViewStore.getRoomId(),
|
||
|
});
|
||
|
},
|
||
|
|
||
|
render: function() {
|
||
|
if (ActiveWidgetStore.getPersistentWidgetId()) {
|
||
|
const persistentWidgetInRoomId = ActiveWidgetStore.getRoomId(ActiveWidgetStore.getPersistentWidgetId());
|
||
|
if (this.state.roomId !== persistentWidgetInRoomId) {
|
||
|
const persistentWidgetInRoom = MatrixClientPeg.get().getRoom(persistentWidgetInRoomId);
|
||
|
// get the widget data
|
||
|
const appEvent = WidgetUtils.getRoomWidgets(persistentWidgetInRoom).find((ev) => {
|
||
|
return ev.getStateKey() === ActiveWidgetStore.getPersistentWidgetId();
|
||
|
});
|
||
|
const app = WidgetUtils.makeAppConfig(
|
||
|
appEvent.getStateKey(), appEvent.getContent(), appEvent.sender, persistentWidgetInRoomId,
|
||
|
);
|
||
|
const capWhitelist = WidgetUtils.getCapWhitelistForAppTypeInRoomId(app.type, persistentWidgetInRoomId);
|
||
|
const AppTile = sdk.getComponent('elements.AppTile');
|
||
|
return <AppTile
|
||
|
key={app.id}
|
||
|
id={app.id}
|
||
|
url={app.url}
|
||
|
name={app.name}
|
||
|
type={app.type}
|
||
|
fullWidth={true}
|
||
|
room={persistentWidgetInRoom}
|
||
|
userId={MatrixClientPeg.get().credentials.userId}
|
||
|
show={true}
|
||
|
creatorUserId={app.creatorUserId}
|
||
|
widgetPageTitle={(app.data && app.data.title) ? app.data.title : ''}
|
||
|
waitForIframeLoad={app.waitForIframeLoad}
|
||
|
whitelistCapabilities={capWhitelist}
|
||
|
showDelete={false}
|
||
|
showMinimise={false}
|
||
|
miniMode={true}
|
||
|
/>;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
},
|
||
|
});
|
||
|
|