diff --git a/src/WidgetMessaging.js b/src/WidgetMessaging.js index 934f9bc3f2..1b66dd89dd 100644 --- a/src/WidgetMessaging.js +++ b/src/WidgetMessaging.js @@ -253,8 +253,10 @@ export default class WidgetMessaging extends MatrixPostMessageApi { // Message endpoint already registered console.warn("Endpoint already registered"); return; + } else { + console.warn(`Adding widget messaging endpoint for ${widgetId}`); + global.mxWidgetMessagingMessageEndpoints.push(endpoint); } - global.mxWidgetMessagingMessageEndpoints.push(endpoint); } } @@ -322,6 +324,9 @@ export default class WidgetMessaging extends MatrixPostMessageApi { api: "widget", version: WIDGET_API_VERSION, }); + } else if (action === 'sticker_message') { + console.warn('got widget sticker message', widgetId); + dis.dispatch({action: 'sticker_message', data: event.data.data}); } else { console.warn("Widget postMessage event unhandled"); this.sendError(event, {message: "The postMessage was unhandled"}); diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index a5e5273b82..7980e100ba 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -459,8 +459,11 @@ module.exports = React.createClass({ case 'message_sent': this._checkIfAlone(this.state.room); break; - case 'inject_sticker': - this.injectSticker(payload.url, payload.info, payload.text); + case 'post_sticker_message': + this.injectSticker( + payload.data.content.url, + payload.data.content.info, + payload.data.description || payload.data.name); break; case 'picture_snapshot': this.uploadFile(payload.file); diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 2fbb30ff90..9e24c12cd5 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -333,7 +333,7 @@ export default React.createClass({ * Called when widget iframe has finished loading */ _onLoaded() { - // console.warn("App frame", this.refs.appFrame.contentWindow); + console.warn("App frame loaded", this.props.id); this.widgetMessaging = new WidgetMessaging(this.props.id, this.refs.appFrame.contentWindow); this.widgetMessaging.startListening(); this.widgetMessaging.addEndpoint(this.props.id, this.props.url); @@ -345,8 +345,22 @@ export default React.createClass({ console.log("Failed to get widget capabilities", this.widgetId, err); }); this.setState({loading: false}); + + dis.register(this._onAction); }, + _onAction(payload) { + switch (payload) { + case payload.action === 'sticker_message': + if (this._hasCapability('sticker_message')) { + dis.dispatch({action: 'post_sticker_message', data: payload.data}); + } else { + console.warn('Ignoring sticker message. Invalid capability'); + } + break; + } + }, + /** * Set remote content title on AppTile * @param {string} url Url to check for title