From: ThibG Date: Tue, 2 Jan 2018 13:24:52 +0000 (+0100) Subject: Display a warning when composing unlisted toots with something looking like a hashtag... X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=b6af88192ff48372c5f6ed1321f21d99aaffcd3f;p=mastodon.git Display a warning when composing unlisted toots with something looking like a hashtag (#6132) --- diff --git a/app/javascript/mastodon/features/compose/containers/warning_container.js b/app/javascript/mastodon/features/compose/containers/warning_container.js index d34471a3e..b9f280958 100644 --- a/app/javascript/mastodon/features/compose/containers/warning_container.js +++ b/app/javascript/mastodon/features/compose/containers/warning_container.js @@ -5,20 +5,27 @@ import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { me } from '../../../initial_state'; +const APPROX_HASHTAG_RE = /(?:^|[^\/\)\w])#(\S+)/i; + const mapStateToProps = state => ({ needsLockWarning: state.getIn(['compose', 'privacy']) === 'private' && !state.getIn(['accounts', me, 'locked']), + hashtagWarning: state.getIn(['compose', 'privacy']) !== 'public' && APPROX_HASHTAG_RE.test(state.getIn(['compose', 'text'])), }); -const WarningWrapper = ({ needsLockWarning }) => { +const WarningWrapper = ({ needsLockWarning, hashtagWarning }) => { if (needsLockWarning) { return }} />} />; } + if (hashtagWarning) { + return } />; + } return null; }; WarningWrapper.propTypes = { needsLockWarning: PropTypes.bool, + hashtagWarning: PropTypes.bool, }; export default connect(mapStateToProps)(WarningWrapper);