If no bug_report_endpoint_url, hide rageshaking from the App

This commit is contained in:
Michael Telatynski 2020-09-15 15:49:25 +01:00
parent 9a3c30b1f1
commit 6c166f0560
5 changed files with 33 additions and 15 deletions

View file

@ -43,6 +43,7 @@ import { ensureDMExists } from "./createRoom";
import { ViewUserPayload } from "./dispatcher/payloads/ViewUserPayload";
import { Action } from "./dispatcher/actions";
import { EffectiveMembership, getEffectiveMembership, leaveRoomBehaviour } from "./utils/membership";
import SdkConfig from "./SdkConfig";
// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816
interface HTMLInputEvent extends Event {
@ -87,6 +88,7 @@ interface ICommandOpts {
runFn?: RunFn;
category: string;
hideCompletionAfterSpace?: boolean;
isEnabled?(): boolean;
}
export class Command {
@ -97,6 +99,7 @@ export class Command {
runFn: undefined | RunFn;
category: string;
hideCompletionAfterSpace: boolean;
_isEnabled?: () => boolean;
constructor(opts: ICommandOpts) {
this.command = opts.command;
@ -106,6 +109,7 @@ export class Command {
this.runFn = opts.runFn;
this.category = opts.category || CommandCategories.other;
this.hideCompletionAfterSpace = opts.hideCompletionAfterSpace || false;
this._isEnabled = opts.isEnabled;
}
getCommand() {
@ -125,6 +129,10 @@ export class Command {
getUsage() {
return _t('Usage') + ': ' + this.getCommandWithArgs();
}
isEnabled() {
return this._isEnabled ? this._isEnabled() : true;
}
}
function reject(error) {
@ -971,6 +979,7 @@ export const Commands = [
command: "rageshake",
aliases: ["bugreport"],
description: _td("Send a bug report with logs"),
isEnabled: () => !!SdkConfig.get().bug_report_endpoint_url,
args: "<description>",
runFn: function(roomId, args) {
return success(
@ -1048,7 +1057,7 @@ Commands.forEach(cmd => {
});
});
export function parseCommandString(input) {
export function parseCommandString(input: string) {
// trim any trailing whitespace, as it can confuse the parser for
// IRC-style commands
input = input.replace(/\s+$/, '');
@ -1075,10 +1084,10 @@ export function parseCommandString(input) {
* processing the command, or 'promise' if a request was sent out.
* Returns null if the input didn't match a command.
*/
export function getCommand(roomId, input) {
export function getCommand(roomId: string, input: string) {
const {cmd, args} = parseCommandString(input);
if (CommandMap.has(cmd)) {
if (CommandMap.has(cmd) && CommandMap.get(cmd).isEnabled()) {
return () => CommandMap.get(cmd).run(roomId, args, cmd);
}
}