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';
10 const getMentionedUsernames
= createSelector(state
=> state
.getIn(['compose', 'text']), text
=> text
.match(/(?:^|[^\/\w])@([a-z0-9_]+@[a-z0-9\.\-]+)/ig));
12 const getMentionedDomains
= createSelector(getMentionedUsernames
, mentionedUsernamesWithDomains
=> {
13 return OrderedSet(mentionedUsernamesWithDomains
!== null ? mentionedUsernamesWithDomains
.map(item
=> item
.split('@')[2]) : []);
16 const mapStateToProps
= state
=> {
17 const mentionedUsernames
= getMentionedUsernames(state
);
18 const mentionedUsernamesWithDomains
= getMentionedDomains(state
);
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']),
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
) {
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
}}
45 WarningWrapper
.propTypes
= {
46 needsLeakWarning: PropTypes
.bool
,
47 needsLockWarning: PropTypes
.bool
,
48 mentionedDomains: ImmutablePropTypes
.orderedSet
.isRequired
,
51 export default connect(mapStateToProps
)(WarningWrapper
);