]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/compose/containers/warning_container.js
Improve eslint rules (#3147)
[mastodon.git] / app / javascript / mastodon / features / compose / containers / warning_container.js
1 import React from 'react';
2 import ImmutablePropTypes from 'react-immutable-proptypes';
3 import { connect } from 'react-redux';
4 import Warning from '../components/warning';
5 import { createSelector } from 'reselect';
6 import PropTypes from 'prop-types';
7 import { FormattedMessage } from 'react-intl';
8 import { OrderedSet } from 'immutable';
9
10 const getMentionedUsernames = createSelector(state => state.getIn(['compose', 'text']), text => text.match(/(?:^|[^\/\w])@([a-z0-9_]+@[a-z0-9\.\-]+)/ig));
11
12 const getMentionedDomains = createSelector(getMentionedUsernames, mentionedUsernamesWithDomains => {
13 return OrderedSet(mentionedUsernamesWithDomains !== null ? mentionedUsernamesWithDomains.map(item => item.split('@')[2]) : []);
14 });
15
16 const mapStateToProps = state => {
17 const mentionedUsernames = getMentionedUsernames(state);
18 const mentionedUsernamesWithDomains = getMentionedDomains(state);
19
20 return {
21 needsLeakWarning: (state.getIn(['compose', 'privacy']) === 'private' || state.getIn(['compose', 'privacy']) === 'direct') && mentionedUsernames !== null,
22 mentionedDomains: mentionedUsernamesWithDomains,
23 needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', state.getIn(['meta', 'me']), 'locked']),
24 };
25 };
26
27 const WarningWrapper = ({ needsLeakWarning, needsLockWarning, mentionedDomains }) => {
28 if (needsLockWarning) {
29 return <Warning message={<FormattedMessage id='compose_form.lock_disclaimer' defaultMessage='Your account is not {locked}. Anyone can follow you to view your follower-only posts.' values={{ locked: <a href='/settings/profile'><FormattedMessage id='compose_form.lock_disclaimer.lock' defaultMessage='locked' /></a> }} />} />;
30 } else if (needsLeakWarning) {
31 return (
32 <Warning
33 message={<FormattedMessage
34 id='compose_form.privacy_disclaimer'
35 defaultMessage='Your private status will be delivered to mentioned users on {domains}. Do you trust {domainsCount, plural, one {that server} other {those servers}}? Post privacy only works on Mastodon instances. If {domains} {domainsCount, plural, one {is not a Mastodon instance} other {are not Mastodon instances}}, there will be no indication that your post is private, and it may be boosted or otherwise made visible to unintended recipients.'
36 values={{ domains: <strong>{mentionedDomains.join(', ')}</strong>, domainsCount: mentionedDomains.size }}
37 />}
38 />
39 );
40 }
41
42 return null;
43 };
44
45 WarningWrapper.propTypes = {
46 needsLeakWarning: PropTypes.bool,
47 needsLockWarning: PropTypes.bool,
48 mentionedDomains: ImmutablePropTypes.orderedSet.isRequired,
49 };
50
51 export default connect(mapStateToProps)(WarningWrapper);
This page took 0.404408 seconds and 5 git commands to generate.