You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.9 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import Warning from '../components/warning';
  4. import PropTypes from 'prop-types';
  5. import { FormattedMessage } from 'react-intl';
  6. import { me } from '../../../initial_state';
  7. const APPROX_HASHTAG_RE = /(?:^|[^\/\)\w])#(\w*[a-zA-Z·]\w*)/i;
  8. const mapStateToProps = state => ({
  9. needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', me, 'locked']),
  10. hashtagWarning: state.getIn(['compose', 'privacy']) !== 'public' && APPROX_HASHTAG_RE.test(state.getIn(['compose', 'text'])),
  11. directMessageWarning: state.getIn(['compose', 'privacy']) === 'direct',
  12. });
  13. const WarningWrapper = ({ needsLockWarning, hashtagWarning, directMessageWarning }) => {
  14. if (needsLockWarning) {
  15. 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> }} />} />;
  16. }
  17. if (hashtagWarning) {
  18. return <Warning message={<FormattedMessage id='compose_form.hashtag_warning' defaultMessage="This toot won't be listed under any hashtag as it is unlisted. Only public toots can be searched by hashtag." />} />;
  19. }
  20. if (directMessageWarning) {
  21. const message = (
  22. <span>
  23. <FormattedMessage id='compose_form.direct_message_warning' defaultMessage='This toot will only be sent to all the mentioned users.' /> <a href='/terms' target='_blank'><FormattedMessage id='compose_form.direct_message_warning_learn_more' defaultMessage='Learn more' /></a>
  24. </span>
  25. );
  26. return <Warning message={message} />;
  27. }
  28. return null;
  29. };
  30. WarningWrapper.propTypes = {
  31. needsLockWarning: PropTypes.bool,
  32. hashtagWarning: PropTypes.bool,
  33. directMessageWarning: PropTypes.bool,
  34. };
  35. export default connect(mapStateToProps)(WarningWrapper);