Disable all widget assets on widget removal.

pull/21833/head
Richard Lewis 2018-02-24 00:10:28 +00:00
parent 332892fee6
commit 86461bc88f
2 changed files with 37 additions and 0 deletions

View File

@ -148,6 +148,33 @@ class ScalarAuthClient {
return defer.promise;
}
disableWidgetAssets(widgetType, widgetId) {
let url = SdkConfig.get().integrations_rest_url + '/widgets/set_assets_state';
url = this.getStarterLink(url);
return new Promise((resolve, reject) => {
request({
method: 'GET',
uri: url,
json: true,
qs: {
'widget_type': widgetType,
'widget_id': widgetId,
'state': 'disable',
},
}, (err, response, body) => {
if (err) {
reject(err);
} else if (response.statusCode / 100 !== 2) {
reject({statusCode: response.statusCode});
} else if (!body) {
reject(new Error("Failed to set widget assets state"));
} else {
resolve();
}
});
});
}
getScalarInterfaceUrlForRoom(room, screen, id) {
const roomId = room.roomId;
const roomName = room.name;

View File

@ -55,6 +55,15 @@ export default class Stickerpack extends React.Component {
_removeStickerpackWidgets() {
console.warn('Removing stickerpack widgets');
if (this.widgetId) {
this.scalarClient.disableWidgetAssets('stickerpack', this.widgetId).then(() => {
console.warn('Assets disabled');
}).catch((err) => {
console.error('Failed to disable assets');
});
} else {
console.warn('No widget ID specified, not disabling assets');
}
Widgets.removeStickerpackWidgets();
this._getStickerPickerWidget();
this.stickersMenu.close();
@ -151,6 +160,7 @@ export default class Stickerpack extends React.Component {
// Default content to show if stickerpack widget not added
console.warn("No available sticker picker widgets");
stickersContent = this.defaultStickersContent;
this.widgetId = null;
this.forceUpdate();
}
this.setState({