2019-08-08 18:39:15 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React, {PureComponent} from 'react';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2019-08-08 18:39:15 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import {MatrixEvent} from "matrix-js-sdk";
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
2020-01-22 17:07:16 +03:00
|
|
|
import SdkConfig from '../../../SdkConfig';
|
|
|
|
import Markdown from '../../../Markdown';
|
2019-08-08 18:39:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A dialog for reporting an event.
|
|
|
|
*/
|
|
|
|
export default class ReportEventDialog extends PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
mxEvent: PropTypes.instanceOf(MatrixEvent).isRequired,
|
|
|
|
onFinished: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2019-12-17 20:26:12 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-08-08 18:39:15 +03:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
reason: "",
|
|
|
|
busy: false,
|
|
|
|
err: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_onReasonChange = ({target: {value: reason}}) => {
|
|
|
|
this.setState({ reason });
|
|
|
|
};
|
|
|
|
|
|
|
|
_onCancel = () => {
|
|
|
|
this.props.onFinished(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
_onSubmit = async () => {
|
|
|
|
if (!this.state.reason || !this.state.reason.trim()) {
|
|
|
|
this.setState({
|
|
|
|
err: _t("Please fill why you're reporting."),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
busy: true,
|
|
|
|
err: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const ev = this.props.mxEvent;
|
|
|
|
await MatrixClientPeg.get().reportEvent(ev.getRoomId(), ev.getId(), -100, this.state.reason.trim());
|
|
|
|
this.props.onFinished(true);
|
|
|
|
} catch (e) {
|
|
|
|
this.setState({
|
|
|
|
busy: false,
|
|
|
|
err: e.message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
|
|
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
|
|
|
const Loader = sdk.getComponent('elements.Spinner');
|
|
|
|
const Field = sdk.getComponent('elements.Field');
|
|
|
|
|
|
|
|
let error = null;
|
|
|
|
if (this.state.err) {
|
|
|
|
error = <div className="error">
|
|
|
|
{this.state.err}
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
let progress = null;
|
|
|
|
if (this.state.busy) {
|
|
|
|
progress = (
|
|
|
|
<div className="progress">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-22 17:07:16 +03:00
|
|
|
const adminMessageMD =
|
|
|
|
SdkConfig.get().reportEvent &&
|
|
|
|
SdkConfig.get().reportEvent.adminMessageMD;
|
|
|
|
let adminMessage;
|
|
|
|
if (adminMessageMD) {
|
2020-01-23 01:08:34 +03:00
|
|
|
const html = new Markdown(adminMessageMD).toHTML({ externalLinks: true });
|
2020-01-22 17:07:16 +03:00
|
|
|
adminMessage = <p dangerouslySetInnerHTML={{ __html: html }} />;
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:39:15 +03:00
|
|
|
return (
|
|
|
|
<BaseDialog
|
|
|
|
className="mx_BugReportDialog"
|
|
|
|
onFinished={this.props.onFinished}
|
2019-09-12 14:52:11 +03:00
|
|
|
title={_t('Report Content to Your Homeserver Administrator')}
|
2019-08-08 18:39:15 +03:00
|
|
|
contentId='mx_ReportEventDialog'
|
|
|
|
>
|
|
|
|
<div className="mx_ReportEventDialog" id="mx_ReportEventDialog">
|
2019-09-12 14:52:11 +03:00
|
|
|
<p>
|
|
|
|
{
|
|
|
|
_t("Reporting this message will send its unique 'event ID' to the administrator of " +
|
|
|
|
"your homeserver. If messages in this room are encrypted, your homeserver " +
|
|
|
|
"administrator will not be able to read the message text or view any files or images.")
|
|
|
|
}
|
|
|
|
</p>
|
2020-01-22 17:07:16 +03:00
|
|
|
{adminMessage}
|
2019-08-08 18:39:15 +03:00
|
|
|
<Field
|
|
|
|
id="mx_ReportEventDialog_reason"
|
|
|
|
className="mx_ReportEventDialog_reason"
|
|
|
|
element="textarea"
|
|
|
|
label={_t("Reason")}
|
|
|
|
rows={5}
|
|
|
|
onChange={this._onReasonChange}
|
|
|
|
value={this.state.reason}
|
|
|
|
disabled={this.state.busy}
|
|
|
|
/>
|
|
|
|
{progress}
|
|
|
|
{error}
|
|
|
|
</div>
|
2019-08-08 18:47:16 +03:00
|
|
|
<DialogButtons
|
|
|
|
primaryButton={_t("Send report")}
|
|
|
|
onPrimaryButtonClick={this._onSubmit}
|
|
|
|
focus={true}
|
|
|
|
onCancel={this._onCancel}
|
|
|
|
disabled={this.state.busy}
|
2019-08-08 18:39:15 +03:00
|
|
|
/>
|
|
|
|
</BaseDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|