Convert to using im.vector.integration_manager for IM widget

This avoids us having to throw the entirety of MSC1957 into the queue, particularly when we're only using a third of the MSC.
This commit is contained in:
Travis Ralston 2019-08-14 08:57:38 -06:00
parent 02a4121401
commit 8b1c90a01e
2 changed files with 16 additions and 11 deletions

View File

@ -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);
}
/**

View File

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