From 86461bc88f7b663fd69d327da5abd0a6f80df860 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Sat, 24 Feb 2018 00:10:28 +0000 Subject: [PATCH] Disable all widget assets on widget removal. --- src/ScalarAuthClient.js | 27 +++++++++++++++++++++++ src/components/views/rooms/Stickerpack.js | 10 +++++++++ 2 files changed, 37 insertions(+) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index c3fcf80308..fea7ee9aa4 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -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; diff --git a/src/components/views/rooms/Stickerpack.js b/src/components/views/rooms/Stickerpack.js index 2163d89f76..f20c581171 100644 --- a/src/components/views/rooms/Stickerpack.js +++ b/src/components/views/rooms/Stickerpack.js @@ -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({