From b63edcb390e6bfafaaa6b1771f7b3ec319807134 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Tue, 13 Jun 2017 15:33:17 +0200 Subject: [PATCH] AppTile: Support deletion of apps from room state --- src/components/views/elements/AppTile.js | 20 ++++++++++++++++++++ src/components/views/rooms/AppsDrawer.js | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 90208cd548..3f81ff5067 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -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() { diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 504221f894..816b813da1 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -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} />);