mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 05:04:57 +08:00
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
This commit is contained in:
parent
c715f72745
commit
e87bda9f37
@ -133,7 +133,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";
|
||||
@ -161,6 +160,7 @@
|
||||
@import "./views/elements/_InlineSpinner.scss";
|
||||
@import "./views/elements/_InteractiveTooltip.scss";
|
||||
@import "./views/elements/_InviteReason.scss";
|
||||
@import "./views/elements/_LabelledCheckbox.scss";
|
||||
@import "./views/elements/_ManageIntegsButton.scss";
|
||||
@import "./views/elements/_MiniAvatarUploader.scss";
|
||||
@import "./views/elements/_Pill.scss";
|
||||
|
@ -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;
|
||||
@ -64,10 +60,5 @@ limitations under the License.
|
||||
border-radius: $font-15px;
|
||||
}
|
||||
}
|
||||
|
||||
.mx_SettingsFlag_label {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 Travis Ralston
|
||||
Copyright 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.
|
||||
@ -14,15 +14,26 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
.mx_WidgetOpenIDPermissionsDialog .mx_SettingsFlag {
|
||||
.mx_ToggleSwitch {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
margin-right: 8px;
|
||||
.mx_LabelledCheckbox {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
.mx_Checkbox {
|
||||
margin-top: 3px; // visually align with label text
|
||||
}
|
||||
|
||||
.mx_SettingsFlag_label {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
.mx_LabelledCheckbox_labels {
|
||||
flex: 1;
|
||||
|
||||
.mx_LabelledCheckbox_label {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.mx_LabelledCheckbox_byline {
|
||||
display: block;
|
||||
padding-top: $spacing-4;
|
||||
color: $muted-fg-color;
|
||||
font-size: $font-11px;
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||
Copyright 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.
|
||||
@ -30,6 +31,7 @@ import BaseDialog from "./BaseDialog";
|
||||
import DialogButtons from "../elements/DialogButtons";
|
||||
import Field from "../elements/Field";
|
||||
import Spinner from "../elements/Spinner";
|
||||
import LabelledCheckbox from "../elements/LabelledCheckbox";
|
||||
|
||||
interface IProps extends IDialogProps {
|
||||
mxEvent: MatrixEvent;
|
||||
@ -42,6 +44,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
|
||||
}
|
||||
|
||||
const MODERATED_BY_STATE_EVENT_TYPE = [
|
||||
@ -160,9 +163,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 });
|
||||
@ -232,6 +240,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);
|
||||
@ -242,7 +259,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
public render() {
|
||||
let error = null;
|
||||
if (this.state.err) {
|
||||
error = <div className="error">
|
||||
@ -259,6 +276,14 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
|
||||
);
|
||||
}
|
||||
|
||||
const ignoreUserCheckbox = <LabelledCheckbox
|
||||
value={this.state.ignoreUserToo}
|
||||
label={_t("Ignore user")}
|
||||
byline={_t("Check if you want to hide all current and future messages from this user.")}
|
||||
onChange={this.onIgnoreUserTooChanged}
|
||||
disabled={this.state.busy}
|
||||
/>;
|
||||
|
||||
const adminMessageMD = SdkConfig
|
||||
.getObject("report_event")?.get("admin_message_md", "adminMessageMD");
|
||||
let adminMessage;
|
||||
@ -387,6 +412,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
|
||||
/>
|
||||
{ progress }
|
||||
{ error }
|
||||
{ ignoreUserCheckbox }
|
||||
</div>
|
||||
<DialogButtons
|
||||
primaryButton={_t("Send report")}
|
||||
@ -428,6 +454,7 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
|
||||
/>
|
||||
{ progress }
|
||||
{ error }
|
||||
{ ignoreUserCheckbox }
|
||||
</div>
|
||||
<DialogButtons
|
||||
primaryButton={_t("Send report")}
|
||||
|
44
src/components/views/elements/LabelledCheckbox.tsx
Normal file
44
src/components/views/elements/LabelledCheckbox.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright 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.
|
||||
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 from "react";
|
||||
|
||||
import StyledCheckbox from "./StyledCheckbox";
|
||||
|
||||
interface IProps {
|
||||
// The value for the checkbox
|
||||
value: boolean;
|
||||
// The translated label for the checkbox
|
||||
label: string;
|
||||
// Optional translated string to show below the checkbox
|
||||
byline?: string;
|
||||
// Whether or not to disable the checkbox
|
||||
disabled?: boolean;
|
||||
// The function to call when the value changes
|
||||
onChange(checked: boolean): void;
|
||||
}
|
||||
|
||||
const LabelledCheckbox: React.FC<IProps> = ({ value, label, byline, disabled, onChange }) => {
|
||||
return <label className="mx_LabelledCheckbox">
|
||||
<StyledCheckbox disabled={disabled} checked={value} onChange={e => onChange(e.target.checked)} />
|
||||
<div className="mx_LabelledCheckbox_labels">
|
||||
<span className="mx_LabelledCheckbox_label">{ label }</span>
|
||||
{ byline ? <span className="mx_LabelledCheckbox_byline">{ byline }</span> : null }
|
||||
</div>
|
||||
</label>;
|
||||
};
|
||||
|
||||
export default LabelledCheckbox;
|
@ -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.
|
||||
@ -15,6 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import classNames from "classnames";
|
||||
|
||||
import ToggleSwitch from "./ToggleSwitch";
|
||||
|
||||
@ -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>;
|
||||
@ -52,7 +53,9 @@ 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, {
|
||||
"mx_SettingsFlag_toggleInFront": this.props.toggleInFront,
|
||||
});
|
||||
return (
|
||||
<div className={classes}>
|
||||
{ firstPart }
|
||||
|
@ -2677,6 +2677,8 @@
|
||||
"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>.",
|
||||
"Email (optional)": "Email (optional)",
|
||||
"Please fill why you're reporting.": "Please fill why you're reporting.",
|
||||
"Ignore user": "Ignore user",
|
||||
"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.",
|
||||
"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.",
|
||||
"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.",
|
||||
"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.",
|
||||
|
124
test/components/views/elements/LabelledCheckbox-test.tsx
Normal file
124
test/components/views/elements/LabelledCheckbox-test.tsx
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright 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.
|
||||
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 from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import LabelledCheckbox from "../../../../src/components/views/elements/LabelledCheckbox";
|
||||
|
||||
// Fake random strings to give a predictable snapshot for checkbox IDs
|
||||
jest.mock(
|
||||
'matrix-js-sdk/src/randomstring',
|
||||
() => {
|
||||
return {
|
||||
randomString: () => "abdefghi",
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
describe('<LabelledCheckbox />', () => {
|
||||
type CompProps = React.ComponentProps<typeof LabelledCheckbox>;
|
||||
const getComponent = (props: CompProps) => mount(<LabelledCheckbox {...props} />);
|
||||
type CompClass = ReturnType<typeof getComponent>;
|
||||
|
||||
const getCheckbox = (component: CompClass) => component.find(`input[type="checkbox"]`);
|
||||
const getLabel = (component: CompClass) => component.find(`.mx_LabelledCheckbox_label`);
|
||||
const getByline = (component: CompClass) => component.find(`.mx_LabelledCheckbox_byline`);
|
||||
|
||||
const isChecked = (checkbox: ReturnType<typeof getCheckbox>) => checkbox.is(`[checked=true]`);
|
||||
const isDisabled = (checkbox: ReturnType<typeof getCheckbox>) => checkbox.is(`[disabled=true]`);
|
||||
const getText = (span: ReturnType<typeof getLabel>) => span.length > 0 ? span.at(0).text() : null;
|
||||
|
||||
test.each([null, "this is a byline"])(
|
||||
"should render with byline of %p",
|
||||
(byline) => {
|
||||
const props: CompProps = {
|
||||
label: "Hello world",
|
||||
value: true,
|
||||
byline: byline,
|
||||
onChange: jest.fn(),
|
||||
};
|
||||
const component = getComponent(props);
|
||||
const checkbox = getCheckbox(component);
|
||||
|
||||
expect(component).toMatchSnapshot();
|
||||
expect(isChecked(checkbox)).toBe(true);
|
||||
expect(isDisabled(checkbox)).toBe(false);
|
||||
expect(getText(getLabel(component))).toBe(props.label);
|
||||
expect(getText(getByline(component))).toBe(byline);
|
||||
},
|
||||
);
|
||||
|
||||
it('should support unchecked by default', () => {
|
||||
const props: CompProps = {
|
||||
label: "Hello world",
|
||||
value: false,
|
||||
onChange: jest.fn(),
|
||||
};
|
||||
const component = getComponent(props);
|
||||
|
||||
expect(isChecked(getCheckbox(component))).toBe(false);
|
||||
});
|
||||
|
||||
it('should be possible to disable the checkbox', () => {
|
||||
const props: CompProps = {
|
||||
label: "Hello world",
|
||||
value: false,
|
||||
disabled: true,
|
||||
onChange: jest.fn(),
|
||||
};
|
||||
const component = getComponent(props);
|
||||
|
||||
expect(isDisabled(getCheckbox(component))).toBe(true);
|
||||
});
|
||||
|
||||
it('should emit onChange calls', () => {
|
||||
const props: CompProps = {
|
||||
label: "Hello world",
|
||||
value: false,
|
||||
onChange: jest.fn(),
|
||||
};
|
||||
const component = getComponent(props);
|
||||
|
||||
expect(props.onChange).not.toHaveBeenCalled();
|
||||
|
||||
act(() => {
|
||||
getCheckbox(component).simulate('change');
|
||||
});
|
||||
|
||||
expect(props.onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should react to value and disabled prop changes', () => {
|
||||
const props: CompProps = {
|
||||
label: "Hello world",
|
||||
value: false,
|
||||
onChange: jest.fn(),
|
||||
};
|
||||
const component = getComponent(props);
|
||||
let checkbox = getCheckbox(component);
|
||||
|
||||
expect(isChecked(checkbox)).toBe(false);
|
||||
expect(isDisabled(checkbox)).toBe(false);
|
||||
|
||||
component.setProps({ value: true, disabled: true });
|
||||
checkbox = getCheckbox(component); // refresh reference to checkbox
|
||||
|
||||
expect(isChecked(checkbox)).toBe(true);
|
||||
expect(isDisabled(checkbox)).toBe(true);
|
||||
});
|
||||
});
|
@ -0,0 +1,108 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<LabelledCheckbox /> should render with byline of "this is a byline" 1`] = `
|
||||
<LabelledCheckbox
|
||||
byline="this is a byline"
|
||||
label="Hello world"
|
||||
onChange={[MockFunction]}
|
||||
value={true}
|
||||
>
|
||||
<label
|
||||
className="mx_LabelledCheckbox"
|
||||
>
|
||||
<StyledCheckbox
|
||||
checked={true}
|
||||
className=""
|
||||
onChange={[Function]}
|
||||
>
|
||||
<span
|
||||
className="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
|
||||
>
|
||||
<input
|
||||
checked={true}
|
||||
id="checkbox_abdefghi"
|
||||
onChange={[Function]}
|
||||
type="checkbox"
|
||||
/>
|
||||
<label
|
||||
htmlFor="checkbox_abdefghi"
|
||||
>
|
||||
<div
|
||||
className="mx_Checkbox_background"
|
||||
>
|
||||
<div
|
||||
className="mx_Checkbox_checkmark"
|
||||
/>
|
||||
</div>
|
||||
<div />
|
||||
</label>
|
||||
</span>
|
||||
</StyledCheckbox>
|
||||
<div
|
||||
className="mx_LabelledCheckbox_labels"
|
||||
>
|
||||
<span
|
||||
className="mx_LabelledCheckbox_label"
|
||||
>
|
||||
Hello world
|
||||
</span>
|
||||
<span
|
||||
className="mx_LabelledCheckbox_byline"
|
||||
>
|
||||
this is a byline
|
||||
</span>
|
||||
</div>
|
||||
</label>
|
||||
</LabelledCheckbox>
|
||||
`;
|
||||
|
||||
exports[`<LabelledCheckbox /> should render with byline of null 1`] = `
|
||||
<LabelledCheckbox
|
||||
byline={null}
|
||||
label="Hello world"
|
||||
onChange={[MockFunction]}
|
||||
value={true}
|
||||
>
|
||||
<label
|
||||
className="mx_LabelledCheckbox"
|
||||
>
|
||||
<StyledCheckbox
|
||||
checked={true}
|
||||
className=""
|
||||
onChange={[Function]}
|
||||
>
|
||||
<span
|
||||
className="mx_Checkbox mx_Checkbox_hasKind mx_Checkbox_kind_solid"
|
||||
>
|
||||
<input
|
||||
checked={true}
|
||||
id="checkbox_abdefghi"
|
||||
onChange={[Function]}
|
||||
type="checkbox"
|
||||
/>
|
||||
<label
|
||||
htmlFor="checkbox_abdefghi"
|
||||
>
|
||||
<div
|
||||
className="mx_Checkbox_background"
|
||||
>
|
||||
<div
|
||||
className="mx_Checkbox_checkmark"
|
||||
/>
|
||||
</div>
|
||||
<div />
|
||||
</label>
|
||||
</span>
|
||||
</StyledCheckbox>
|
||||
<div
|
||||
className="mx_LabelledCheckbox_labels"
|
||||
>
|
||||
<span
|
||||
className="mx_LabelledCheckbox_label"
|
||||
>
|
||||
Hello world
|
||||
</span>
|
||||
</div>
|
||||
</label>
|
||||
</LabelledCheckbox>
|
||||
`;
|
@ -34,7 +34,7 @@ exports[`<LocationShareMenu /> with live location disabled goes to labs flag scr
|
||||
value={false}
|
||||
>
|
||||
<div
|
||||
className="mx_SettingsFlag "
|
||||
className="mx_SettingsFlag"
|
||||
>
|
||||
<span
|
||||
className="mx_SettingsFlag_label"
|
||||
|
@ -10,7 +10,7 @@ exports[`<Notifications /> main notification switches email switches renders ema
|
||||
value={false}
|
||||
>
|
||||
<div
|
||||
className="mx_SettingsFlag "
|
||||
className="mx_SettingsFlag"
|
||||
>
|
||||
<span
|
||||
className="mx_SettingsFlag_label"
|
||||
@ -67,7 +67,7 @@ exports[`<Notifications /> main notification switches renders only enable notifi
|
||||
value={false}
|
||||
>
|
||||
<div
|
||||
className="mx_SettingsFlag "
|
||||
className="mx_SettingsFlag"
|
||||
>
|
||||
<span
|
||||
className="mx_SettingsFlag_label"
|
||||
|
@ -100,7 +100,7 @@ exports[`<SpaceSettingsVisibilityTab /> renders container 1`] = `
|
||||
class="mx_SettingsTab_toggleWithDescription"
|
||||
>
|
||||
<div
|
||||
class="mx_SettingsFlag "
|
||||
class="mx_SettingsFlag"
|
||||
>
|
||||
<span
|
||||
class="mx_SettingsFlag_label"
|
||||
|
Loading…
Reference in New Issue
Block a user