Fix widgets for all other sources too

This commit is contained in:
Travis Ralston 2020-04-09 15:25:11 -06:00
parent dc92f557fd
commit 4510499987
3 changed files with 18 additions and 2 deletions

View file

@ -239,6 +239,7 @@ import WidgetUtils from './utils/WidgetUtils';
import RoomViewStore from './stores/RoomViewStore';
import { _t } from './languageHandler';
import {IntegrationManagers} from "./integrations/IntegrationManagers";
import {WidgetType} from "./widgets/WidgetType";
function sendResponse(event, res) {
const data = JSON.parse(JSON.stringify(event.data));
@ -290,7 +291,7 @@ function inviteUser(event, roomId, userId) {
function setWidget(event, roomId) {
const widgetId = event.data.widget_id;
const widgetType = event.data.type;
let widgetType = event.data.type;
const widgetUrl = event.data.url;
const widgetName = event.data.name; // optional
const widgetData = event.data.data; // optional
@ -322,6 +323,9 @@ function setWidget(event, roomId) {
}
}
// convert the widget type to a known widget type
widgetType = WidgetType.fromString(widgetType);
if (userWidget) {
WidgetUtils.setUserWidget(widgetId, widgetType, widgetUrl, widgetName, widgetData).then(() => {
sendResponse(event, {

View file

@ -35,6 +35,7 @@ import { abbreviateUrl } from './utils/UrlUtils';
import { getDefaultIdentityServerUrl, useDefaultIdentityServer } from './utils/IdentityServerUtils';
import {isPermalinkHost, parsePermalink} from "./utils/permalinks/Permalinks";
import {inviteUsersToRoom} from "./RoomInvite";
import { WidgetType } from "./widgets/WidgetType";
// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816
interface HTMLInputEvent extends Event {
@ -775,7 +776,7 @@ export const Commands = [
const nowMs = (new Date()).getTime();
const widgetId = encodeURIComponent(`${roomId}_${userId}_${nowMs}`);
return success(WidgetUtils.setRoomWidget(
roomId, widgetId, "m.custom", args, "Custom Widget", {}));
roomId, widgetId, WidgetType.CUSTOM, args, "Custom Widget", {}));
} else {
return reject(_t("You cannot modify widgets in this room."));
}

View file

@ -16,6 +16,7 @@ limitations under the License.
export class WidgetType {
public static readonly JITSI = new WidgetType("m.jitsi", "jitsi");
public static readonly CUSTOM = new WidgetType("m.custom", "m.custom");
constructor(public readonly preferred: string, public readonly legacy: string) {
}
@ -23,4 +24,14 @@ export class WidgetType {
public matches(type: string): boolean {
return type === this.preferred || type === this.legacy;
}
static fromString(type: string): WidgetType {
// First try and match it against something we're already aware of
const known = Object.values(WidgetType).filter(v => v instanceof WidgetType);
const knownMatch = known.find(w => w.matches(type));
if (knownMatch) return knownMatch;
// If that fails, invent a new widget type
return new WidgetType(type, type);
}
}