From b6af88192ff48372c5f6ed1321f21d99aaffcd3f Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 2 Jan 2018 14:24:52 +0100 Subject: [PATCH] Display a warning when composing unlisted toots with something looking like a hashtag (#6132) --- .../features/compose/containers/warning_container.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/features/compose/containers/warning_container.js b/app/javascript/mastodon/features/compose/containers/warning_container.js index d34471a3e99..b9f28095810 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);