2020-03-27 13:59:38 -07:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import Warning from '../components/warning' ;
import PropTypes from 'prop-types' ;
import { FormattedMessage } from 'react-intl' ;
2021-10-13 12:35:34 -07:00
import { Link } from 'react-router-dom' ;
2020-03-27 13:59:38 -07:00
const APPROX _HASHTAG _RE = /(?:^|[^\/\)\w])#(\w*[a-zA-Z·]\w*)/i ;
2020-04-01 19:20:47 -07:00
const mapStateToProps = state => {
const me = state . get ( 'me' ) ;
return {
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' ] ) ) ,
directMessageWarning : state . getIn ( [ 'compose' , 'privacy' ] ) === 'direct' ,
2020-04-14 11:44:40 -07:00
} ;
2020-04-01 19:20:47 -07:00
} ;
2020-03-27 13:59:38 -07:00
const WarningWrapper = ( { needsLockWarning , hashtagWarning , directMessageWarning } ) => {
if ( needsLockWarning ) {
2021-10-13 12:35:34 -07:00
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 : < Link to = '/settings/profile' > < FormattedMessage id = 'compose_form.lock_disclaimer.lock' defaultMessage = 'locked' / > < /Link> }} / > } / > ;
2020-03-27 13:59:38 -07:00
}
if ( hashtagWarning ) {
return < Warning message = { < FormattedMessage id = 'compose_form.hashtag_warning' defaultMessage = "This post won't be listed under any hashtag as it is unlisted. Only public posts can be searched by hashtag." / > } / > ;
}
if ( directMessageWarning ) {
const message = (
< span >
2021-10-13 12:32:38 -07:00
< FormattedMessage id = 'compose_form.direct_message_warning' defaultMessage = 'This post will only be sent to the mentioned users.' / >
{ /* <a href='/about/tos' target='_blank'><FormattedMessage id='compose_form.direct_message_warning_learn_more' defaultMessage='Learn more' /></a> */ }
2020-03-27 13:59:38 -07:00
< / s p a n >
) ;
return < Warning message = { message } / > ;
}
return null ;
} ;
WarningWrapper . propTypes = {
needsLockWarning : PropTypes . bool ,
hashtagWarning : PropTypes . bool ,
directMessageWarning : PropTypes . bool ,
} ;
export default connect ( mapStateToProps ) ( WarningWrapper ) ;