Move destroyPersistentWidget to store

This commit is contained in:
David Baker 2018-07-24 16:50:34 +01:00
parent acc767a479
commit 7044410a13
3 changed files with 15 additions and 18 deletions

View file

@ -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() {

View file

@ -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;

View file

@ -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.