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

Commit e87bda9

Browse files
authored
Add an option to ignore (block) a user when reporting their events (#8471)
* Add an option to ignore (block) a user when reporting their events This is primarily useful if the content being reported really doesn't belong on your screen, and the room moderators are slow to react. Ideally we'd use the word "block" instead of "ignore", but we call it "ignore user" everywhere else. See https://github.com/vector-im/element-web/issues/19590 for further context on the word choice. This change includes a minor refactor to the styles of labelled toggles (for reusability). * Appease the linter * Use a checkbox instead of toggle in the dialog * Update classnames handling for toggle switch * Appease the linter
1 parent c715f72 commit e87bda9

File tree

13 files changed

+350
-27
lines changed

13 files changed

+350
-27
lines changed

res/css/_components.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
@import "./views/dialogs/_UploadConfirmDialog.scss";
134134
@import "./views/dialogs/_UserSettingsDialog.scss";
135135
@import "./views/dialogs/_WidgetCapabilitiesPromptDialog.scss";
136-
@import "./views/dialogs/_WidgetOpenIDPermissionsDialog.scss";
137136
@import "./views/dialogs/security/_AccessSecretStorageDialog.scss";
138137
@import "./views/dialogs/security/_CreateCrossSigningDialog.scss";
139138
@import "./views/dialogs/security/_CreateKeyBackupDialog.scss";
@@ -161,6 +160,7 @@
161160
@import "./views/elements/_InlineSpinner.scss";
162161
@import "./views/elements/_InteractiveTooltip.scss";
163162
@import "./views/elements/_InviteReason.scss";
163+
@import "./views/elements/_LabelledCheckbox.scss";
164164
@import "./views/elements/_ManageIntegsButton.scss";
165165
@import "./views/elements/_MiniAvatarUploader.scss";
166166
@import "./views/elements/_Pill.scss";

res/css/views/dialogs/_WidgetCapabilitiesPromptDialog.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ limitations under the License.
4646
font-size: $font-12px;
4747

4848
.mx_ToggleSwitch {
49-
display: inline-block;
50-
vertical-align: middle;
51-
margin-right: 8px;
52-
5349
// downsize the switch + ball
5450
width: $font-32px;
5551
height: $font-15px;
@@ -64,10 +60,5 @@ limitations under the License.
6460
border-radius: $font-15px;
6561
}
6662
}
67-
68-
.mx_SettingsFlag_label {
69-
display: inline-block;
70-
vertical-align: middle;
71-
}
7263
}
7364
}
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2019 Travis Ralston
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -14,15 +14,26 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
.mx_WidgetOpenIDPermissionsDialog .mx_SettingsFlag {
18-
.mx_ToggleSwitch {
19-
display: inline-block;
20-
vertical-align: middle;
21-
margin-right: 8px;
17+
.mx_LabelledCheckbox {
18+
display: flex;
19+
flex-direction: row;
20+
21+
.mx_Checkbox {
22+
margin-top: 3px; // visually align with label text
2223
}
2324

24-
.mx_SettingsFlag_label {
25-
display: inline-block;
26-
vertical-align: middle;
25+
.mx_LabelledCheckbox_labels {
26+
flex: 1;
27+
28+
.mx_LabelledCheckbox_label {
29+
vertical-align: middle;
30+
}
31+
32+
.mx_LabelledCheckbox_byline {
33+
display: block;
34+
padding-top: $spacing-4;
35+
color: $muted-fg-color;
36+
font-size: $font-11px;
37+
}
2738
}
2839
}

res/css/views/elements/_SettingsFlag.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ limitations under the License.
2424
.mx_ToggleSwitch {
2525
flex: 0 0 auto;
2626
}
27+
28+
&.mx_SettingsFlag_toggleInFront {
29+
.mx_ToggleSwitch {
30+
display: inline-block;
31+
vertical-align: middle;
32+
margin-right: 8px;
33+
}
34+
35+
.mx_SettingsFlag_label {
36+
display: inline-block;
37+
vertical-align: middle;
38+
}
39+
}
2740
}
2841

2942
.mx_SettingsFlag_label {

src/components/views/dialogs/ReportEventDialog.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2019 Michael Telatynski <[email protected]>
3+
Copyright 2022 The Matrix.org Foundation C.I.C.
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -30,6 +31,7 @@ import BaseDialog from "./BaseDialog";
3031
import DialogButtons from "../elements/DialogButtons";
3132
import Field from "../elements/Field";
3233
import Spinner from "../elements/Spinner";
34+
import LabelledCheckbox from "../elements/LabelledCheckbox";
3335

3436
interface IProps extends IDialogProps {
3537
mxEvent: MatrixEvent;
@@ -42,6 +44,7 @@ interface IState {
4244
err?: string;
4345
// If we know it, the nature of the abuse, as specified by MSC3215.
4446
nature?: ExtendedNature;
47+
ignoreUserToo: boolean; // if true, user will be ignored/blocked on submit
4548
}
4649

4750
const MODERATED_BY_STATE_EVENT_TYPE = [
@@ -160,9 +163,14 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
160163
err: null,
161164
// If specified, the nature of the abuse, as specified by MSC3215.
162165
nature: null,
166+
ignoreUserToo: false, // default false, for now. Could easily be argued as default true
163167
};
164168
}
165169

170+
private onIgnoreUserTooChanged = (newVal: boolean): void => {
171+
this.setState({ ignoreUserToo: newVal });
172+
};
173+
166174
// The user has written down a freeform description of the abuse.
167175
private onReasonChange = ({ target: { value: reason } }): void => {
168176
this.setState({ reason });
@@ -232,6 +240,15 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
232240
// Report to homeserver admin through the dedicated Matrix API.
233241
await client.reportEvent(ev.getRoomId(), ev.getId(), -100, this.state.reason.trim());
234242
}
243+
244+
// if the user should also be ignored, do that
245+
if (this.state.ignoreUserToo) {
246+
await client.setIgnoredUsers([
247+
...client.getIgnoredUsers(),
248+
ev.getSender(),
249+
]);
250+
}
251+
235252
this.props.onFinished(true);
236253
} catch (e) {
237254
logger.error(e);
@@ -242,7 +259,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
242259
}
243260
};
244261

245-
render() {
262+
public render() {
246263
let error = null;
247264
if (this.state.err) {
248265
error = <div className="error">
@@ -259,6 +276,14 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
259276
);
260277
}
261278

279+
const ignoreUserCheckbox = <LabelledCheckbox
280+
value={this.state.ignoreUserToo}
281+
label={_t("Ignore user")}
282+
byline={_t("Check if you want to hide all current and future messages from this user.")}
283+
onChange={this.onIgnoreUserTooChanged}
284+
disabled={this.state.busy}
285+
/>;
286+
262287
const adminMessageMD = SdkConfig
263288
.getObject("report_event")?.get("admin_message_md", "adminMessageMD");
264289
let adminMessage;
@@ -387,6 +412,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
387412
/>
388413
{ progress }
389414
{ error }
415+
{ ignoreUserCheckbox }
390416
</div>
391417
<DialogButtons
392418
primaryButton={_t("Send report")}
@@ -428,6 +454,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
428454
/>
429455
{ progress }
430456
{ error }
457+
{ ignoreUserCheckbox }
431458
</div>
432459
<DialogButtons
433460
primaryButton={_t("Send report")}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from "react";
18+
19+
import StyledCheckbox from "./StyledCheckbox";
20+
21+
interface IProps {
22+
// The value for the checkbox
23+
value: boolean;
24+
// The translated label for the checkbox
25+
label: string;
26+
// Optional translated string to show below the checkbox
27+
byline?: string;
28+
// Whether or not to disable the checkbox
29+
disabled?: boolean;
30+
// The function to call when the value changes
31+
onChange(checked: boolean): void;
32+
}
33+
34+
const LabelledCheckbox: React.FC<IProps> = ({ value, label, byline, disabled, onChange }) => {
35+
return <label className="mx_LabelledCheckbox">
36+
<StyledCheckbox disabled={disabled} checked={value} onChange={e => onChange(e.target.checked)} />
37+
<div className="mx_LabelledCheckbox_labels">
38+
<span className="mx_LabelledCheckbox_label">{ label }</span>
39+
{ byline ? <span className="mx_LabelledCheckbox_byline">{ byline }</span> : null }
40+
</div>
41+
</label>;
42+
};
43+
44+
export default LabelledCheckbox;

src/components/views/elements/LabelledToggleSwitch.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
2+
Copyright 2019 - 2022 The Matrix.org Foundation C.I.C.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React from "react";
18+
import classNames from "classnames";
1819

1920
import ToggleSwitch from "./ToggleSwitch";
2021

@@ -35,7 +36,7 @@ interface IProps {
3536
}
3637

3738
export default class LabelledToggleSwitch extends React.PureComponent<IProps> {
38-
render() {
39+
public render() {
3940
// This is a minimal version of a SettingsFlag
4041

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

55-
const classes = `mx_SettingsFlag ${this.props.className || ""}`;
56+
const classes = classNames("mx_SettingsFlag", this.props.className, {
57+
"mx_SettingsFlag_toggleInFront": this.props.toggleInFront,
58+
});
5659
return (
5760
<div className={classes}>
5861
{ firstPart }

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,6 +2677,8 @@
26772677
"Just a heads up, if you don't add an email and forget your password, you could <b>permanently lose access to your account</b>.": "Just a heads up, if you don't add an email and forget your password, you could <b>permanently lose access to your account</b>.",
26782678
"Email (optional)": "Email (optional)",
26792679
"Please fill why you're reporting.": "Please fill why you're reporting.",
2680+
"Ignore user": "Ignore user",
2681+
"Check if you want to hide all current and future messages from this user.": "Check if you want to hide all current and future messages from this user.",
26802682
"What this user is writing is wrong.\nThis will be reported to the room moderators.": "What this user is writing is wrong.\nThis will be reported to the room moderators.",
26812683
"This user is displaying toxic behaviour, for instance by insulting other users or sharing adult-only content in a family-friendly room or otherwise violating the rules of this room.\nThis will be reported to the room moderators.": "This user is displaying toxic behaviour, for instance by insulting other users or sharing adult-only content in a family-friendly room or otherwise violating the rules of this room.\nThis will be reported to the room moderators.",
26822684
"This user is displaying illegal behaviour, for instance by doxing people or threatening violence.\nThis will be reported to the room moderators who may escalate this to legal authorities.": "This user is displaying illegal behaviour, for instance by doxing people or threatening violence.\nThis will be reported to the room moderators who may escalate this to legal authorities.",

0 commit comments

Comments
 (0)