Merge pull request #4458 from matrix-org/travis/fix-sticker-picker-add

Use WidgetType more often to avoid breaking new sticker pickers
pull/21833/head
Travis Ralston 2020-04-23 08:18:12 -06:00 committed by GitHub
commit 35dd892dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 13 deletions

View File

@ -23,6 +23,7 @@ import request from "browser-request";
import * as Matrix from 'matrix-js-sdk'; import * as Matrix from 'matrix-js-sdk';
import SdkConfig from "./SdkConfig"; import SdkConfig from "./SdkConfig";
import {WidgetType} from "./widgets/WidgetType";
// The version of the integration manager API we're intending to work with // The version of the integration manager API we're intending to work with
const imApiVersion = "1.1"; const imApiVersion = "1.1";
@ -235,20 +236,20 @@ export default class ScalarAuthClient {
* Mark all assets associated with the specified widget as "disabled" in the * Mark all assets associated with the specified widget as "disabled" in the
* integration manager database. * integration manager database.
* This can be useful to temporarily prevent purchased assets from being displayed. * This can be useful to temporarily prevent purchased assets from being displayed.
* @param {string} widgetType [description] * @param {WidgetType} widgetType The Widget Type to disable assets for
* @param {string} widgetId [description] * @param {string} widgetId The widget ID to disable assets for
* @return {Promise} Resolves on completion * @return {Promise} Resolves on completion
*/ */
disableWidgetAssets(widgetType, widgetId) { disableWidgetAssets(widgetType: WidgetType, widgetId) {
let url = this.apiUrl + '/widgets/set_assets_state'; let url = this.apiUrl + '/widgets/set_assets_state';
url = this.getStarterLink(url); url = this.getStarterLink(url);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
request({ request({
method: 'GET', method: 'GET', // XXX: Actions shouldn't be GET requests
uri: url, uri: url,
json: true, json: true,
qs: { qs: {
'widget_type': widgetType, 'widget_type': widgetType.preferred,
'widget_id': widgetId, 'widget_id': widgetId,
'state': 'disable', 'state': 'disable',
}, },

View File

@ -26,8 +26,7 @@ import PersistedElement from "../elements/PersistedElement";
import {IntegrationManagers} from "../../../integrations/IntegrationManagers"; import {IntegrationManagers} from "../../../integrations/IntegrationManagers";
import SettingsStore from "../../../settings/SettingsStore"; import SettingsStore from "../../../settings/SettingsStore";
import {ContextMenu} from "../../structures/ContextMenu"; import {ContextMenu} from "../../structures/ContextMenu";
import {WidgetType} from "../../../widgets/WidgetType";
const widgetType = 'm.stickerpicker';
// This should be below the dialog level (4000), but above the rest of the UI (1000-2000). // This should be below the dialog level (4000), but above the rest of the UI (1000-2000).
// We sit in a context menu, so this should be given to the context menu. // We sit in a context menu, so this should be given to the context menu.
@ -87,7 +86,7 @@ export default class Stickerpicker extends React.Component {
console.log('Removing Stickerpicker widgets'); console.log('Removing Stickerpicker widgets');
if (this.state.widgetId) { if (this.state.widgetId) {
if (scalarClient) { if (scalarClient) {
scalarClient.disableWidgetAssets(widgetType, this.state.widgetId).then(() => { scalarClient.disableWidgetAssets(WidgetType.STICKERPICKER, this.state.widgetId).then(() => {
console.log('Assets disabled'); console.log('Assets disabled');
}).catch((err) => { }).catch((err) => {
console.error('Failed to disable assets'); console.error('Failed to disable assets');
@ -364,13 +363,13 @@ export default class Stickerpicker extends React.Component {
if (SettingsStore.isFeatureEnabled("feature_many_integration_managers")) { if (SettingsStore.isFeatureEnabled("feature_many_integration_managers")) {
IntegrationManagers.sharedInstance().openAll( IntegrationManagers.sharedInstance().openAll(
this.props.room, this.props.room,
`type_${widgetType}`, `type_${WidgetType.STICKERPICKER.preferred}`,
this.state.widgetId, this.state.widgetId,
); );
} else { } else {
IntegrationManagers.sharedInstance().getPrimaryManager().open( IntegrationManagers.sharedInstance().getPrimaryManager().open(
this.props.room, this.props.room,
`type_${widgetType}`, `type_${WidgetType.STICKERPICKER.preferred}`,
this.state.widgetId, this.state.widgetId,
); );
} }

View File

@ -211,9 +211,9 @@ export default class WidgetUtils {
}); });
} }
static setUserWidget(widgetId, widgetType, widgetUrl, widgetName, widgetData) { static setUserWidget(widgetId, widgetType: WidgetType, widgetUrl, widgetName, widgetData) {
const content = { const content = {
type: widgetType, type: widgetType.preferred,
url: widgetUrl, url: widgetUrl,
name: widgetName, name: widgetName,
data: widgetData, data: widgetData,
@ -370,7 +370,7 @@ export default class WidgetUtils {
static addIntegrationManagerWidget(name: string, uiUrl: string, apiUrl: string) { static addIntegrationManagerWidget(name: string, uiUrl: string, apiUrl: string) {
return WidgetUtils.setUserWidget( return WidgetUtils.setUserWidget(
"integration_manager_" + (new Date().getTime()), "integration_manager_" + (new Date().getTime()),
"m.integration_manager", WidgetType.INTEGRATION_MANAGER,
uiUrl, uiUrl,
"Integration Manager: " + name, "Integration Manager: " + name,
{"api_url": apiUrl}, {"api_url": apiUrl},

View File

@ -16,6 +16,8 @@ limitations under the License.
export class WidgetType { export class WidgetType {
public static readonly JITSI = new WidgetType("m.jitsi", "jitsi"); public static readonly JITSI = new WidgetType("m.jitsi", "jitsi");
public static readonly STICKERPICKER = new WidgetType("m.stickerpicker", "m.stickerpicker");
public static readonly INTEGRATION_MANAGER = new WidgetType("m.integration_manager", "m.integration_manager");
public static readonly CUSTOM = new WidgetType("m.custom", "m.custom"); public static readonly CUSTOM = new WidgetType("m.custom", "m.custom");
constructor(public readonly preferred: string, public readonly legacy: string) { constructor(public readonly preferred: string, public readonly legacy: string) {