From 0165ff0bc9b2c9c44a400f72d1c1ab1fb7ab574b Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 9 Apr 2020 16:02:49 -0600 Subject: [PATCH] Allow iframes and Jitsi URLs in /addwidget Fixes https://github.com/vector-im/riot-web/issues/12784 --- package.json | 1 + src/SlashCommands.tsx | 44 ++++++++-- src/widgets/Jitsi.ts | 22 +++++ yarn.lock | 200 ++++-------------------------------------- 4 files changed, 78 insertions(+), 189 deletions(-) diff --git a/package.json b/package.json index 616f3f541e..2bf2b7c5a9 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", "minimist": "^1.2.0", "pako": "^1.0.5", + "parse5": "^5.1.1", "png-chunks-extract": "^1.0.0", "project-name-generator": "^2.1.7", "prop-types": "^15.5.8", diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 0afea63a78..ff9ebbc70a 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -36,6 +36,8 @@ import { getDefaultIdentityServerUrl, useDefaultIdentityServer } from './utils/I import {isPermalinkHost, parsePermalink} from "./utils/permalinks/Permalinks"; import {inviteUsersToRoom} from "./RoomInvite"; import { WidgetType } from "./widgets/WidgetType"; +import { Jitsi } from "./widgets/Jitsi"; +import { parseFragment as parseHtml } from "parse5"; // XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816 interface HTMLInputEvent extends Event { @@ -765,18 +767,50 @@ export const Commands = [ }), new Command({ command: 'addwidget', - args: '', + args: '', description: _td('Adds a custom widget by URL to the room'), - runFn: function(roomId, args) { - if (!args || (!args.startsWith("https://") && !args.startsWith("http://"))) { + runFn: function(roomId, widgetUrl) { + if (!widgetUrl) { + return reject(_t("Please supply a widget URL or embed code")); + } + + // Try and parse out a widget URL from iframes + if (widgetUrl.toLowerCase().startsWith("