AppTile: Support deletion of apps from room state

pull/21833/head
Robert Swain 2017-06-13 15:33:17 +02:00
parent bcb2f8408b
commit b63edcb390
2 changed files with 21 additions and 1 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
'use strict';
const React = require('react');
const MatrixClientPeg = require('../../../MatrixClientPeg');
export default React.createClass({
displayName: 'AppTile',
@ -25,6 +26,7 @@ export default React.createClass({
id: React.PropTypes.string.isRequired,
url: React.PropTypes.string.isRequired,
name: React.PropTypes.string.isRequired,
room: React.PropTypes.object.isRequired,
},
getDefaultProps: function() {
@ -49,6 +51,24 @@ export default React.createClass({
_onDeleteClick: function() {
console.log("Delete widget %s", this.props.id);
const appsStateEvents = this.props.room.currentState.getStateEvents('im.vector.modular.widgets', '');
if (!appsStateEvents) {
return;
}
const appsStateEvent = appsStateEvents.getContent();
if (appsStateEvent[this.props.id]) {
delete appsStateEvent[this.props.id];
MatrixClientPeg.get().sendStateEvent(
this.props.room.roomId,
'im.vector.modular.widgets',
appsStateEvent,
'',
).then(() => {
console.log('Deleted widget');
}, (e) => {
console.error('Failed to delete widget', e);
});
}
},
render: function() {

View File

@ -177,8 +177,8 @@ module.exports = React.createClass({
id={app.id}
url={app.url}
name={app.name}
roomId={this.props.roomId}
fullWidth={arr.length<2 ? true : false}
room={this.props.room}
userId={this.props.userId}
/>);