diff --git a/src/integrations/IntegrationManagers.js b/src/integrations/IntegrationManagers.js index 9b852fe61a..49356676e6 100644 --- a/src/integrations/IntegrationManagers.js +++ b/src/integrations/IntegrationManagers.js @@ -113,13 +113,7 @@ export class IntegrationManagers { await WidgetUtils.removeIntegrationManagerWidgets(); // TODO: TravisR - We should actually be carrying over the discovery response verbatim. - await WidgetUtils.setUserWidget( - "integration_manager_" + (new Date().getTime()), - "m.integration_manager", - manager.uiUrl, - "Integration Manager", - {"api_url": manager.apiUrl}, - ); + await WidgetUtils.addIntegrationManagerWidget(manager.name, manager.uiUrl, manager.apiUrl); } /** diff --git a/src/utils/WidgetUtils.js b/src/utils/WidgetUtils.js index edac449ccf..fb79ec0ae7 100644 --- a/src/utils/WidgetUtils.js +++ b/src/utils/WidgetUtils.js @@ -29,6 +29,9 @@ import SettingsStore from "../settings/SettingsStore"; import ActiveWidgetStore from "../stores/ActiveWidgetStore"; import {IntegrationManagers} from "../integrations/IntegrationManagers"; +// We'll be using im.vector.integration_manager until MSC1957 or similar is accepted. +const IM_WIDGET_TYPES = ["m.integration_manager", "im.vector.integration_manager"]; + /** * Encodes a URI according to a set of template variables. Variables will be * passed through encodeURIComponent. @@ -346,9 +349,7 @@ export default class WidgetUtils { */ static getIntegrationManagerWidgets() { const widgets = WidgetUtils.getUserWidgetsArray(); - // We'll be using im.vector.integration_manager until MSC1957 or similar is accepted. - const imTypes = ["m.integration_manager", "im.vector.integration_manager"]; - return widgets.filter(w => w.content && imTypes.includes(w.content.type)); + return widgets.filter(w => w.content && IM_WIDGET_TYPES.includes(w.content.type)); } static removeIntegrationManagerWidgets() { @@ -358,13 +359,23 @@ export default class WidgetUtils { } const userWidgets = client.getAccountData('m.widgets').getContent() || {}; Object.entries(userWidgets).forEach(([key, widget]) => { - if (widget.content && widget.content.type === 'm.integration_manager') { + if (widget.content && IM_WIDGET_TYPES.includes(widget.content.type)) { delete userWidgets[key]; } }); return client.setAccountData('m.widgets', userWidgets); } + static addIntegrationManagerWidget(name: string, uiUrl: string, apiUrl: string) { + return WidgetUtils.setUserWidget( + "integration_manager_" + (new Date().getTime()), + "im.vector.integration_manager", // TODO: Use m.integration_manager post-MSC1957 + uiUrl, + "Integration Manager: " + name, + {"api_url": apiUrl}, + ); + } + /** * Remove all stickerpicker widgets (stickerpickers are user widgets by nature) * @return {Promise} Resolves on account data updated