Merge pull request #2824 from matrix-org/travis/add-widget-command
Add a command for creating custom widgets without an integration managerpull/21833/head
commit
1a6bebcc1d
|
@ -29,6 +29,7 @@ import * as querystring from "querystring";
|
||||||
import MultiInviter from './utils/MultiInviter';
|
import MultiInviter from './utils/MultiInviter';
|
||||||
import { linkifyAndSanitizeHtml } from './HtmlUtils';
|
import { linkifyAndSanitizeHtml } from './HtmlUtils';
|
||||||
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
||||||
|
import WidgetUtils from "./utils/WidgetUtils";
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
|
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
|
||||||
|
@ -606,6 +607,26 @@ export const CommandMap = {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
addwidget: new Command({
|
||||||
|
name: 'addwidget',
|
||||||
|
args: '<url>',
|
||||||
|
description: _td('Adds a custom widget by URL to the room'),
|
||||||
|
runFn: function(roomId, args) {
|
||||||
|
if (!args || (!args.startsWith("https://") && !args.startsWith("http://"))) {
|
||||||
|
return reject(_t("Please supply a https:// or http:// widget URL"));
|
||||||
|
}
|
||||||
|
if (WidgetUtils.canUserModifyWidgets(roomId)) {
|
||||||
|
const userId = MatrixClientPeg.get().getUserId();
|
||||||
|
const nowMs = (new Date()).getTime();
|
||||||
|
const widgetId = encodeURIComponent(`${roomId}_${userId}_${nowMs}`);
|
||||||
|
return success(WidgetUtils.setRoomWidget(
|
||||||
|
roomId, widgetId, "m.custom", args, "Custom Widget", {}));
|
||||||
|
} else {
|
||||||
|
return reject(_t("You cannot modify widgets in this room."));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
// Verify a user, device, and pubkey tuple
|
// Verify a user, device, and pubkey tuple
|
||||||
verify: new Command({
|
verify: new Command({
|
||||||
name: 'verify',
|
name: 'verify',
|
||||||
|
|
|
@ -161,6 +161,9 @@
|
||||||
"Define the power level of a user": "Define the power level of a user",
|
"Define the power level of a user": "Define the power level of a user",
|
||||||
"Deops user with given id": "Deops user with given id",
|
"Deops user with given id": "Deops user with given id",
|
||||||
"Opens the Developer Tools dialog": "Opens the Developer Tools dialog",
|
"Opens the Developer Tools dialog": "Opens the Developer Tools dialog",
|
||||||
|
"Adds a custom widget by URL to the room": "Adds a custom widget by URL to the room",
|
||||||
|
"Please supply a https:// or http:// widget URL": "Please supply a https:// or http:// widget URL",
|
||||||
|
"You cannot modify widgets in this room.": "You cannot modify widgets in this room.",
|
||||||
"Verifies a user, device, and pubkey tuple": "Verifies a user, device, and pubkey tuple",
|
"Verifies a user, device, and pubkey tuple": "Verifies a user, device, and pubkey tuple",
|
||||||
"Unknown (user, device) pair:": "Unknown (user, device) pair:",
|
"Unknown (user, device) pair:": "Unknown (user, device) pair:",
|
||||||
"Device already verified!": "Device already verified!",
|
"Device already verified!": "Device already verified!",
|
||||||
|
|
Loading…
Reference in New Issue