diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index d6d211a985..66005eb730 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2018 New Vector Ltd +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. @@ -117,6 +118,14 @@ module.exports = createReactClass({ this.closeMenu(); }, + onReportEventClick: function() { + const ReportEventDialog = sdk.getComponent("dialogs.ReportEventDialog"); + Modal.createTrackedDialog('Report Event', '', ReportEventDialog, { + mxEvent: this.props.mxEvent, + }, 'mx_Dialog_reportEvent'); + this.closeMenu(); + }, + onViewSourceClick: function() { const ViewSource = sdk.getComponent('structures.ViewSource'); Modal.createTrackedDialog('View Event Source', '', ViewSource, { @@ -279,6 +288,8 @@ module.exports = createReactClass({ }, render: function() { + const cli = MatrixClientPeg.get(); + const me = cli.getUserId(); const mxEvent = this.props.mxEvent; const eventStatus = mxEvent.status; const editStatus = mxEvent.replacingEvent() && mxEvent.replacingEvent().status; @@ -446,6 +457,15 @@ module.exports = createReactClass({ ; } + let reportEventButton; + if (mxEvent.getSender() !== me) { + reportEventButton = ( +
+ { _t('Report Content') } +
+ ); + } + return (
{ resendButton } @@ -464,6 +484,7 @@ module.exports = createReactClass({ { externalURLButton } { collapseReplyThread } { e2eInfo } + { reportEventButton }
); }, diff --git a/src/components/views/dialogs/ReportEventDialog.js b/src/components/views/dialogs/ReportEventDialog.js new file mode 100644 index 0000000000..394e5ad47d --- /dev/null +++ b/src/components/views/dialogs/ReportEventDialog.js @@ -0,0 +1,137 @@ +/* +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'; +import sdk from '../../../index'; +import { _t } from '../../../languageHandler'; +import PropTypes from "prop-types"; +import {MatrixEvent} from "matrix-js-sdk"; +import MatrixClientPeg from "../../../MatrixClientPeg"; + +/* + * A dialog for reporting an event. + */ +export default class ReportEventDialog extends PureComponent { + static propTypes = { + mxEvent: PropTypes.instanceOf(MatrixEvent).isRequired, + onFinished: PropTypes.func.isRequired, + }; + + constructor(props, context) { + super(props, context); + + 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 =
+ {this.state.err} +
; + } + + let progress = null; + if (this.state.busy) { + progress = ( +
+ +
+ ); + } + + return ( + +
+

+ { + _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.") + } +

+ + + {progress} + {error} +
+ +
+ ); + } +} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 2c38f918a0..872b7bd3c4 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1305,6 +1305,10 @@ "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.": "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.", "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.": "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.", "Report bugs & give feedback": "Report bugs & give feedback", + "Please fill why you're reporting.": "Please fill why you're reporting.", + "Report Content to Your Homeserver Administrator": "Report Content to Your Homeserver Administrator", + "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.": "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.", + "Send report": "Send report", "Room Settings - %(roomName)s": "Room Settings - %(roomName)s", "Failed to upgrade room": "Failed to upgrade room", "The room upgrade could not be completed": "The room upgrade could not be completed", @@ -1426,6 +1430,7 @@ "Source URL": "Source URL", "Collapse Reply Thread": "Collapse Reply Thread", "End-to-end encryption information": "End-to-end encryption information", + "Report Content": "Report Content", "Failed to set Direct Message status of room": "Failed to set Direct Message status of room", "Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s", "All messages (noisy)": "All messages (noisy)",