2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2017-02-15 04:59:26 +09:00
|
|
|
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2017-07-11 08:00:14 +09:00
|
|
|
import { OrderedSet } from 'immutable';
|
2023-05-24 00:15:17 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-06-28 01:07:21 +09:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2023-10-25 02:45:08 +09:00
|
|
|
import { ReactComponent as CloseIcon } from '@material-symbols/svg-600/outlined/close.svg';
|
|
|
|
|
2023-05-24 00:15:17 +09:00
|
|
|
import { submitReport } from 'mastodon/actions/reports';
|
|
|
|
import { fetchServer } from 'mastodon/actions/server';
|
|
|
|
import { expandAccountTimeline } from 'mastodon/actions/timelines';
|
2023-05-09 10:11:56 +09:00
|
|
|
import { IconButton } from 'mastodon/components/icon_button';
|
2022-02-24 04:03:46 +09:00
|
|
|
import Category from 'mastodon/features/report/category';
|
|
|
|
import Comment from 'mastodon/features/report/comment';
|
2023-05-24 00:15:17 +09:00
|
|
|
import Rules from 'mastodon/features/report/rules';
|
|
|
|
import Statuses from 'mastodon/features/report/statuses';
|
2022-02-24 04:03:46 +09:00
|
|
|
import Thanks from 'mastodon/features/report/thanks';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { makeGetAccount } from 'mastodon/selectors';
|
2017-02-15 04:59:26 +09:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2018-03-02 12:36:00 +09:00
|
|
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
2017-02-15 04:59:26 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
2022-02-24 04:03:46 +09:00
|
|
|
const mapStateToProps = (state, { accountId }) => ({
|
|
|
|
account: getAccount(state, accountId),
|
|
|
|
});
|
2017-02-15 04:59:26 +09:00
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
|
|
|
|
2018-09-15 00:59:48 +09:00
|
|
|
class ReportModal extends ImmutablePureComponent {
|
2017-05-12 21:44:10 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
2022-02-24 04:03:46 +09:00
|
|
|
accountId: PropTypes.string.isRequired,
|
|
|
|
statusId: PropTypes.string,
|
2017-05-12 21:44:10 +09:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-05-21 00:31:47 +09:00
|
|
|
intl: PropTypes.object.isRequired,
|
2023-11-04 00:00:03 +09:00
|
|
|
account: ImmutablePropTypes.record.isRequired,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2022-02-24 04:03:46 +09:00
|
|
|
state = {
|
|
|
|
step: 'category',
|
|
|
|
selectedStatusIds: OrderedSet(this.props.statusId ? [this.props.statusId] : []),
|
2023-07-11 01:26:56 +09:00
|
|
|
selectedDomains: OrderedSet(),
|
2022-02-24 04:03:46 +09:00
|
|
|
comment: '',
|
|
|
|
category: null,
|
|
|
|
selectedRuleIds: OrderedSet(),
|
|
|
|
isSubmitting: false,
|
|
|
|
isSubmitted: false,
|
|
|
|
};
|
2018-02-28 14:54:55 +09:00
|
|
|
|
2017-06-28 01:07:21 +09:00
|
|
|
handleSubmit = () => {
|
2022-02-24 04:03:46 +09:00
|
|
|
const { dispatch, accountId } = this.props;
|
2023-07-11 01:26:56 +09:00
|
|
|
const { selectedStatusIds, selectedDomains, comment, category, selectedRuleIds } = this.state;
|
2022-02-24 04:03:46 +09:00
|
|
|
|
|
|
|
this.setState({ isSubmitting: true });
|
|
|
|
|
|
|
|
dispatch(submitReport({
|
|
|
|
account_id: accountId,
|
|
|
|
status_ids: selectedStatusIds.toArray(),
|
2023-08-24 21:06:27 +09:00
|
|
|
forward_to_domains: selectedDomains.toArray(),
|
2022-02-24 04:03:46 +09:00
|
|
|
comment,
|
2023-07-11 01:26:56 +09:00
|
|
|
forward: selectedDomains.size > 0,
|
2022-02-24 04:03:46 +09:00
|
|
|
category,
|
|
|
|
rule_ids: selectedRuleIds.toArray(),
|
|
|
|
}, this.handleSuccess, this.handleFail));
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSuccess = () => {
|
|
|
|
this.setState({ isSubmitting: false, isSubmitted: true, step: 'thanks' });
|
|
|
|
};
|
|
|
|
|
|
|
|
handleFail = () => {
|
|
|
|
this.setState({ isSubmitting: false });
|
|
|
|
};
|
|
|
|
|
|
|
|
handleStatusToggle = (statusId, checked) => {
|
|
|
|
const { selectedStatusIds } = this.state;
|
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
this.setState({ selectedStatusIds: selectedStatusIds.add(statusId) });
|
|
|
|
} else {
|
|
|
|
this.setState({ selectedStatusIds: selectedStatusIds.remove(statusId) });
|
|
|
|
}
|
|
|
|
};
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2023-07-11 01:26:56 +09:00
|
|
|
handleDomainToggle = (domain, checked) => {
|
|
|
|
if (checked) {
|
|
|
|
this.setState((state) => ({ selectedDomains: state.selectedDomains.add(domain) }));
|
|
|
|
} else {
|
|
|
|
this.setState((state) => ({ selectedDomains: state.selectedDomains.remove(domain) }));
|
|
|
|
}
|
|
|
|
};
|
2022-02-24 04:03:46 +09:00
|
|
|
|
2023-07-11 01:26:56 +09:00
|
|
|
handleRuleToggle = (ruleId, checked) => {
|
2022-02-24 04:03:46 +09:00
|
|
|
if (checked) {
|
2023-07-11 01:26:56 +09:00
|
|
|
this.setState((state) => ({ selectedRuleIds: state.selectedRuleIds.add(ruleId) }));
|
2022-02-24 04:03:46 +09:00
|
|
|
} else {
|
2023-07-11 01:26:56 +09:00
|
|
|
this.setState((state) => ({ selectedRuleIds: state.selectedRuleIds.remove(ruleId) }));
|
2018-06-04 20:09:52 +09:00
|
|
|
}
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2018-06-04 20:09:52 +09:00
|
|
|
|
2022-02-24 04:03:46 +09:00
|
|
|
handleChangeCategory = category => {
|
|
|
|
this.setState({ category });
|
|
|
|
};
|
|
|
|
|
|
|
|
handleChangeComment = comment => {
|
|
|
|
this.setState({ comment });
|
|
|
|
};
|
|
|
|
|
|
|
|
handleNextStep = step => {
|
|
|
|
this.setState({ step });
|
|
|
|
};
|
|
|
|
|
2017-06-28 01:07:21 +09:00
|
|
|
componentDidMount () {
|
2022-02-24 04:03:46 +09:00
|
|
|
const { dispatch, accountId } = this.props;
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2022-02-24 04:03:46 +09:00
|
|
|
dispatch(expandAccountTimeline(accountId, { withReplies: true }));
|
2022-10-05 10:47:56 +09:00
|
|
|
dispatch(fetchServer());
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-02-15 04:59:26 +09:00
|
|
|
|
|
|
|
render () {
|
2022-02-24 04:03:46 +09:00
|
|
|
const {
|
|
|
|
accountId,
|
|
|
|
account,
|
|
|
|
intl,
|
|
|
|
onClose,
|
|
|
|
} = this.props;
|
2017-02-15 04:59:26 +09:00
|
|
|
|
|
|
|
if (!account) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-02-24 04:03:46 +09:00
|
|
|
const {
|
|
|
|
step,
|
|
|
|
selectedStatusIds,
|
|
|
|
selectedRuleIds,
|
2023-07-11 01:26:56 +09:00
|
|
|
selectedDomains,
|
2022-02-24 04:03:46 +09:00
|
|
|
comment,
|
|
|
|
category,
|
|
|
|
isSubmitting,
|
|
|
|
isSubmitted,
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
const domain = account.get('acct').split('@')[1];
|
|
|
|
const isRemote = !!domain;
|
|
|
|
|
|
|
|
let stepComponent;
|
|
|
|
|
|
|
|
switch(step) {
|
|
|
|
case 'category':
|
|
|
|
stepComponent = (
|
|
|
|
<Category
|
|
|
|
onNextStep={this.handleNextStep}
|
|
|
|
startedFrom={this.props.statusId ? 'status' : 'account'}
|
|
|
|
category={category}
|
|
|
|
onChangeCategory={this.handleChangeCategory}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'rules':
|
|
|
|
stepComponent = (
|
|
|
|
<Rules
|
|
|
|
onNextStep={this.handleNextStep}
|
|
|
|
selectedRuleIds={selectedRuleIds}
|
|
|
|
onToggle={this.handleRuleToggle}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'statuses':
|
|
|
|
stepComponent = (
|
|
|
|
<Statuses
|
|
|
|
onNextStep={this.handleNextStep}
|
|
|
|
accountId={accountId}
|
|
|
|
selectedStatusIds={selectedStatusIds}
|
|
|
|
onToggle={this.handleStatusToggle}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'comment':
|
|
|
|
stepComponent = (
|
|
|
|
<Comment
|
|
|
|
onSubmit={this.handleSubmit}
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
isRemote={isRemote}
|
|
|
|
comment={comment}
|
|
|
|
domain={domain}
|
|
|
|
onChangeComment={this.handleChangeComment}
|
2023-07-11 01:26:56 +09:00
|
|
|
statusIds={selectedStatusIds}
|
|
|
|
selectedDomains={selectedDomains}
|
|
|
|
onToggleDomain={this.handleDomainToggle}
|
2022-02-24 04:03:46 +09:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'thanks':
|
|
|
|
stepComponent = (
|
|
|
|
<Thanks
|
|
|
|
submitted={isSubmitted}
|
|
|
|
account={account}
|
|
|
|
onClose={onClose}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2018-02-28 14:54:55 +09:00
|
|
|
|
2017-02-15 04:59:26 +09:00
|
|
|
return (
|
2022-02-24 04:03:46 +09:00
|
|
|
<div className='modal-root__modal report-dialog-modal'>
|
2017-06-28 01:07:21 +09:00
|
|
|
<div className='report-modal__target'>
|
2023-10-25 02:45:08 +09:00
|
|
|
<IconButton className='report-modal__close' title={intl.formatMessage(messages.close)} icon='times' iconComponent={CloseIcon} onClick={onClose} size={20} />
|
2017-06-28 01:07:21 +09:00
|
|
|
<FormattedMessage id='report.target' defaultMessage='Report {target}' values={{ target: <strong>{account.get('acct')}</strong> }} />
|
|
|
|
</div>
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2022-02-24 04:03:46 +09:00
|
|
|
<div className='report-dialog-modal__container'>
|
|
|
|
{stepComponent}
|
2017-06-28 01:07:21 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-15 04:59:26 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2023-03-24 11:17:53 +09:00
|
|
|
|
|
|
|
export default connect(makeMapStateToProps)(injectIntl(ReportModal));
|