import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; import { me } from 'mastodon/initial_state'; import { HASHTAG_PATTERN_REGEX } from 'mastodon/utils/hashtags'; import { MENTION_PATTERN_REGEX } from 'mastodon/utils/mentions'; import Warning from '../components/warning'; const mapStateToProps = state => ({ needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', me, 'locked']), hashtagWarning: !['public', 'public_unlisted', 'login'].includes(state.getIn(['compose', 'privacy'])) && state.getIn(['compose', 'searchability']) !== 'public' && HASHTAG_PATTERN_REGEX.test(state.getIn(['compose', 'text'])), directMessageWarning: state.getIn(['compose', 'privacy']) === 'direct', searchabilityWarning: state.getIn(['compose', 'searchability']) === 'limited', mentionWarning: ['mutual', 'circle', 'limited'].includes(state.getIn(['compose', 'privacy'])) && MENTION_PATTERN_REGEX.test(state.getIn(['compose', 'text'])), limitedPostWarning: ['mutual', 'circle'].includes(state.getIn(['compose', 'privacy'])) && !state.getIn(['compose', 'limited_scope']), }); const WarningWrapper = ({ needsLockWarning, hashtagWarning, directMessageWarning, searchabilityWarning, mentionWarning, limitedPostWarning }) => { if (needsLockWarning) { return }} />} />; } if (hashtagWarning) { return } />; } if (directMessageWarning) { const message = ( ); return ; } if (searchabilityWarning) { return } />; } if (mentionWarning) { return } />; } if (limitedPostWarning) { return } />; } return null; }; WarningWrapper.propTypes = { needsLockWarning: PropTypes.bool, hashtagWarning: PropTypes.bool, directMessageWarning: PropTypes.bool, searchabilityWarning: PropTypes.bool, mentionWarning: PropTypes.bool, limitedPostWarning: PropTypes.bool, }; export default connect(mapStateToProps)(WarningWrapper);