diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 3b8105a0fe..bd88327b7f 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -160,19 +160,10 @@ export default class AppTile extends React.Component { // if it's not remaining on screen, get rid of the PersistedElement container if (!ActiveWidgetStore.getWidgetPersistence(this.props.id)) { - // FIXME: ActiveWidgetStore should probably worry about this? - this._destroyPersistentWidget(); + ActiveWidgetStore.destroyPersistentWidget(); } } - _destroyPersistentWidget() { - const PersistedElement = sdk.getComponent("elements.PersistedElement"); - PersistedElement.destroyElement(this._persistKey); - ActiveWidgetStore.delWidgetMessaging(this.props.id); - ActiveWidgetStore.delWidgetCapabilities(this.props.id); - ActiveWidgetStore.delRoomId(this.props.id); - } - /** * Adds a scalar token to the widget URL, if required * Component initialisation is only complete when this function has resolved @@ -445,8 +436,7 @@ export default class AppTile extends React.Component { this.setState({hasPermissionToLoad: false}); // Force the widget to be non-persistent - ActiveWidgetStore.setWidgetPersistence(this.props.id, false); - this._destroyPersistentWidget(); + ActiveWidgetStore.destroyPersistentWidget(); } formatAppTileName() { diff --git a/src/stores/ActiveWidgetStore.js b/src/stores/ActiveWidgetStore.js index e1b1efaace..53c17d0ee6 100644 --- a/src/stores/ActiveWidgetStore.js +++ b/src/stores/ActiveWidgetStore.js @@ -66,15 +66,21 @@ class ActiveWidgetStore extends EventEmitter { if (ev.getType() !== 'im.vector.modular.widgets') return; if (ev.getStateKey() === this._persistentWidgetId) { - const PersistedElement = sdk.getComponent("elements.PersistedElement"); - PersistedElement.destroyElement('widget_' + ev.getStateKey()); - this.setWidgetPersistence(ev.getStateKey(), false); - this.delWidgetMessaging(ev.getStateKey()); - this.delWidgetCapabilities(ev.getStateKey()); - this.delRoomId(ev.getStateKey()); + this.destroyPersistentWidget(); } } + destroyPersistentWidget() { + const toDeleteId = this._persistentWidgetId; + + const PersistedElement = sdk.getComponent("elements.PersistedElement"); + PersistedElement.destroyElement('widget_' + toDeleteId); + this.setWidgetPersistence(toDeleteId, false); + this.delWidgetMessaging(toDeleteId); + this.delWidgetCapabilities(toDeleteId); + this.delRoomId(toDeleteId); + } + setWidgetPersistence(widgetId, val) { if (this._persistentWidgetId === widgetId && !val) { this._persistentWidgetId = null; diff --git a/src/stores/LifecycleStore.js b/src/stores/LifecycleStore.js index 0d76f06e72..2ce3be5a33 100644 --- a/src/stores/LifecycleStore.js +++ b/src/stores/LifecycleStore.js @@ -1,5 +1,6 @@ /* Copyright 2017 Vector Creations Ltd +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.