warning_container.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import PropTypes from 'prop-types';
  2. import { FormattedMessage } from 'react-intl';
  3. import { connect } from 'react-redux';
  4. import { me } from 'mastodon/initial_state';
  5. import { HASHTAG_PATTERN_REGEX } from 'mastodon/utils/hashtags';
  6. import Warning from '../components/warning';
  7. const mapStateToProps = state => ({
  8. needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', me, 'locked']),
  9. hashtagWarning: state.getIn(['compose', 'privacy']) !== 'public' && HASHTAG_PATTERN_REGEX.test(state.getIn(['compose', 'text'])),
  10. directMessageWarning: state.getIn(['compose', 'privacy']) === 'direct',
  11. });
  12. const WarningWrapper = ({ needsLockWarning, hashtagWarning, directMessageWarning }) => {
  13. if (needsLockWarning) {
  14. 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> }} />} />;
  15. }
  16. if (hashtagWarning) {
  17. return <Warning message={<FormattedMessage id='compose_form.hashtag_warning' defaultMessage="This post won't be listed under any hashtag as it is unlisted. Only public posts can be searched by hashtag." />} />;
  18. }
  19. if (directMessageWarning) {
  20. const message = (
  21. <span>
  22. <FormattedMessage id='compose_form.encryption_warning' defaultMessage='Posts on Mastodon are not end-to-end encrypted. Do not share any dangerous information over Mastodon.' /> <a href='/terms' target='_blank'><FormattedMessage id='compose_form.direct_message_warning_learn_more' defaultMessage='Learn more' /></a>
  23. </span>
  24. );
  25. return <Warning message={message} />;
  26. }
  27. return null;
  28. };
  29. WarningWrapper.propTypes = {
  30. needsLockWarning: PropTypes.bool,
  31. hashtagWarning: PropTypes.bool,
  32. directMessageWarning: PropTypes.bool,
  33. };
  34. export default connect(mapStateToProps)(WarningWrapper);