diff --git a/src/FromWidgetPostMessageApi.js b/src/FromWidgetPostMessageApi.js index 4dd3ea6e6d..61c51d4a20 100644 --- a/src/FromWidgetPostMessageApi.js +++ b/src/FromWidgetPostMessageApi.js @@ -116,10 +116,8 @@ export default class FromWidgetPostMessageApi { const origin = u.protocol + '//' + u.host; if (this.widgetMessagingEndpoints && this.widgetMessagingEndpoints.length > 0) { const length = this.widgetMessagingEndpoints.length; - this.widgetMessagingEndpoints = this.widgetMessagingEndpoints. - filter(function(endpoint) { - return (endpoint.widgetId != widgetId || endpoint.endpointUrl != origin); - }); + this.widgetMessagingEndpoints = this.widgetMessagingEndpoints + .filter((endpoint) => endpoint.widgetId !== widgetId || endpoint.endpointUrl !== origin); return (length > this.widgetMessagingEndpoints.length); } return false; diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 708eb39bd3..959cee7ace 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -339,9 +339,7 @@ export default class AppTile extends React.Component { // Destroy the old widget messaging before starting it back up again. Some widgets // have startup routines that run when they are loaded, so we just need to reinitialize // the messaging for them. - if (ActiveWidgetStore.getWidgetMessaging(this.props.id)) { - ActiveWidgetStore.delWidgetMessaging(this.props.id); - } + ActiveWidgetStore.delWidgetMessaging(this.props.id); this._setupWidgetMessaging(); ActiveWidgetStore.setRoomId(this.props.id, this.props.room.roomId); diff --git a/src/components/views/rooms/Stickerpicker.js b/src/components/views/rooms/Stickerpicker.js index b487c90ae2..a0e3f1b7a9 100644 --- a/src/components/views/rooms/Stickerpicker.js +++ b/src/components/views/rooms/Stickerpicker.js @@ -37,6 +37,8 @@ const STICKERPICKER_Z_INDEX = 3500; const PERSISTED_ELEMENT_KEY = "stickerPicker"; export default class Stickerpicker extends React.Component { + static currentWidget; + constructor(props) { super(props); this._onShowStickersClick = this._onShowStickersClick.bind(this); @@ -130,8 +132,13 @@ export default class Stickerpicker extends React.Component { _updateWidget() { const stickerpickerWidget = WidgetUtils.getStickerpickerWidgets()[0]; + if (!stickerpickerWidget) { + Stickerpicker.currentWidget = null; + this.setState({stickerpickerWidget: null, widgetId: null}); + return; + } - const currentWidget = this.state.stickerpickerWidget; + const currentWidget = Stickerpicker.currentWidget; let currentUrl = null; if (currentWidget && currentWidget.content && currentWidget.content.url) { currentUrl = currentWidget.content.url; @@ -147,6 +154,7 @@ export default class Stickerpicker extends React.Component { PersistedElement.destroyElement(PERSISTED_ELEMENT_KEY); } + Stickerpicker.currentWidget = stickerpickerWidget; this.setState({ stickerpickerWidget, widgetId: stickerpickerWidget ? stickerpickerWidget.id : null, diff --git a/src/stores/ActiveWidgetStore.js b/src/stores/ActiveWidgetStore.js index 89fa6e6936..f0a9f718a2 100644 --- a/src/stores/ActiveWidgetStore.js +++ b/src/stores/ActiveWidgetStore.js @@ -112,6 +112,8 @@ class ActiveWidgetStore extends EventEmitter { } setWidgetMessaging(widgetId, wm) { + // Stop any existing widget messaging first + this.delWidgetMessaging(widgetId); this._widgetMessagingByWidgetId[widgetId] = wm; this.emit('update'); }