Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add an option to ignore (block) a user when reporting their events #8471

Merged
merged 7 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
@import "./views/dialogs/_UploadConfirmDialog.scss";
@import "./views/dialogs/_UserSettingsDialog.scss";
@import "./views/dialogs/_WidgetCapabilitiesPromptDialog.scss";
@import "./views/dialogs/_WidgetOpenIDPermissionsDialog.scss";
@import "./views/dialogs/security/_AccessSecretStorageDialog.scss";
@import "./views/dialogs/security/_CreateCrossSigningDialog.scss";
@import "./views/dialogs/security/_CreateKeyBackupDialog.scss";
Expand Down
9 changes: 0 additions & 9 deletions res/css/views/dialogs/_WidgetCapabilitiesPromptDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ limitations under the License.
font-size: $font-12px;

.mx_ToggleSwitch {
display: inline-block;
vertical-align: middle;
margin-right: 8px;

// downsize the switch + ball
width: $font-32px;
height: $font-15px;
Expand All @@ -64,10 +60,5 @@ limitations under the License.
border-radius: $font-15px;
}
}

.mx_SettingsFlag_label {
display: inline-block;
vertical-align: middle;
}
}
}
28 changes: 0 additions & 28 deletions res/css/views/dialogs/_WidgetOpenIDPermissionsDialog.scss

This file was deleted.

13 changes: 13 additions & 0 deletions res/css/views/elements/_SettingsFlag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ limitations under the License.
.mx_ToggleSwitch {
flex: 0 0 auto;
}

&.mx_SettingsFlag_toggleInFront {
.mx_ToggleSwitch {
display: inline-block;
vertical-align: middle;
margin-right: 8px;
}

.mx_SettingsFlag_label {
display: inline-block;
vertical-align: middle;
}
}
}

.mx_SettingsFlag_label {
Expand Down
32 changes: 31 additions & 1 deletion src/components/views/dialogs/ReportEventDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import BaseDialog from "./BaseDialog";
import DialogButtons from "../elements/DialogButtons";
import Field from "../elements/Field";
import Spinner from "../elements/Spinner";
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";

interface IProps extends IDialogProps {
mxEvent: MatrixEvent;
Expand All @@ -42,6 +43,7 @@ interface IState {
err?: string;
// If we know it, the nature of the abuse, as specified by MSC3215.
nature?: ExtendedNature;
ignoreUserToo: boolean; // if true, user will be ignored/blocked on submit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how I feel about the too - ignoreUser should be fine, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it just didn't feel right to not acknowledge what the flag was doing. Given the context of the dialog, "ignore user" could mean "instead", "in addition to", or "don't file report". If we used the word "block" throughout the application instead, it'd be more than fine to leave it at blockUser.

}

const MODERATED_BY_STATE_EVENT_TYPE = [
Expand Down Expand Up @@ -160,9 +162,14 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
err: null,
// If specified, the nature of the abuse, as specified by MSC3215.
nature: null,
ignoreUserToo: false, // default false, for now. Could easily be argued as default true
};
}

private onIgnoreUserTooChanged = (newVal: boolean): void => {
this.setState({ ignoreUserToo: newVal });
};

// The user has written down a freeform description of the abuse.
private onReasonChange = ({ target: { value: reason } }): void => {
this.setState({ reason });
Expand Down Expand Up @@ -232,6 +239,15 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
// Report to homeserver admin through the dedicated Matrix API.
await client.reportEvent(ev.getRoomId(), ev.getId(), -100, this.state.reason.trim());
}

// if the user should also be ignored, do that
if (this.state.ignoreUserToo) {
await client.setIgnoredUsers([
...client.getIgnoredUsers(),
ev.getSender(),
]);
}

this.props.onFinished(true);
} catch (e) {
logger.error(e);
Expand All @@ -242,7 +258,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
}
};

render() {
public render() {
let error = null;
if (this.state.err) {
error = <div className="error">
Expand Down Expand Up @@ -387,6 +403,13 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
/>
{ progress }
{ error }
<LabelledToggleSwitch
value={this.state.ignoreUserToo}
toggleInFront={true}
disabled={this.state.busy}
onChange={this.onIgnoreUserTooChanged}
label={_t("Ignore the user (hide all current and future messages from this user)")}
/>
</div>
<DialogButtons
primaryButton={_t("Send report")}
Expand Down Expand Up @@ -428,6 +451,13 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
/>
{ progress }
{ error }
<LabelledToggleSwitch
value={this.state.ignoreUserToo}
toggleInFront={true}
disabled={this.state.busy}
onChange={this.onIgnoreUserTooChanged}
label={_t("Ignore the user (hide all current and future messages from this user)")}
/>
</div>
<DialogButtons
primaryButton={_t("Send report")}
Expand Down
10 changes: 7 additions & 3 deletions src/components/views/elements/LabelledToggleSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
Copyright 2019 - 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@ limitations under the License.
*/

import React from "react";
import classNames from "classnames";

import ToggleSwitch from "./ToggleSwitch";

Expand All @@ -35,7 +36,7 @@ interface IProps {
}

export default class LabelledToggleSwitch extends React.PureComponent<IProps> {
render() {
public render() {
// This is a minimal version of a SettingsFlag

let firstPart = <span className="mx_SettingsFlag_label">{ this.props.label }</span>;
Expand All @@ -52,7 +53,10 @@ export default class LabelledToggleSwitch extends React.PureComponent<IProps> {
secondPart = temp;
}

const classes = `mx_SettingsFlag ${this.props.className || ""}`;
const classes = classNames("mx_SettingsFlag", {
[this.props.className ?? ""]: true,
turt2live marked this conversation as resolved.
Show resolved Hide resolved
"mx_SettingsFlag_toggleInFront": this.props.toggleInFront,
});
return (
<div className={classes}>
{ firstPart }
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,7 @@
"Illegal Content": "Illegal Content",
"Spam or propaganda": "Spam or propaganda",
"Report the entire room": "Report the entire room",
"Ignore the user (hide all current and future messages from this user)": "Ignore the user (hide all current and future messages from this user)",
"Send report": "Send report",
"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.",
Expand Down