logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

warning_container.js (1781B)


  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. return <Warning message={<FormattedMessage id='compose_form.direct_message_warning' defaultMessage='This toot will only be visible to all the mentioned users.' />} />;
  22. }
  23. return null;
  24. };
  25. WarningWrapper.propTypes = {
  26. needsLockWarning: PropTypes.bool,
  27. hashtagWarning: PropTypes.bool,
  28. directMessageWarning: PropTypes.bool,
  29. };
  30. export default connect(mapStateToProps)(WarningWrapper);