2017-05-03 09:04:16 +09:00
import React from 'react' ;
2017-04-24 07:38:37 +09:00
import { connect } from 'react-redux' ;
import Warning from '../components/warning' ;
import PropTypes from 'prop-types' ;
import { FormattedMessage } from 'react-intl' ;
2017-10-31 11:27:48 +09:00
import { me } from '../../../initial_state' ;
2017-04-24 07:38:37 +09:00
2020-08-06 05:39:14 +09:00
const buildHashtagRE = ( ) => {
try {
2020-08-07 17:40:33 +09:00
const HASHTAG _SEPARATORS = '_\\u00b7\\u200c' ;
2020-08-06 05:39:14 +09:00
const ALPHA = '\\p{L}\\p{M}' ;
const WORD = '\\p{L}\\p{M}\\p{N}\\p{Pc}' ;
return new RegExp (
'(?:^|[^\\/\\)\\w])#((' +
'[' + WORD + '_]' +
'[' + WORD + HASHTAG _SEPARATORS + ']*' +
'[' + ALPHA + HASHTAG _SEPARATORS + ']' +
'[' + WORD + HASHTAG _SEPARATORS + ']*' +
'[' + WORD + '_]' +
')|(' +
'[' + WORD + '_]*' +
'[' + ALPHA + ']' +
'[' + WORD + '_]*' +
2020-08-07 17:40:33 +09:00
'))' , 'iu' ,
2020-08-06 05:39:14 +09:00
) ;
} catch {
2023-02-13 23:12:14 +09:00
return /(?:^|[^/)\w])#(\w*[a-zA-Z·]\w*)/i ;
2020-08-06 05:39:14 +09:00
}
} ;
const APPROX _HASHTAG _RE = buildHashtagRE ( ) ;
2018-01-02 22:24:52 +09:00
2017-09-28 07:26:33 +09:00
const mapStateToProps = state => ( {
2017-10-31 11:27:48 +09:00
needsLockWarning : state . getIn ( [ 'compose' , 'privacy' ] ) === 'private' && ! state . getIn ( [ 'accounts' , me , 'locked' ] ) ,
2018-01-02 22:24:52 +09:00
hashtagWarning : state . getIn ( [ 'compose' , 'privacy' ] ) !== 'public' && APPROX _HASHTAG _RE . test ( state . getIn ( [ 'compose' , 'text' ] ) ) ,
2018-03-30 02:08:34 +09:00
directMessageWarning : state . getIn ( [ 'compose' , 'privacy' ] ) === 'direct' ,
2017-04-24 07:38:37 +09:00
} ) ;
2018-03-30 02:08:34 +09:00
const WarningWrapper = ( { needsLockWarning , hashtagWarning , directMessageWarning } ) => {
2017-04-24 07:38:37 +09:00
if ( needsLockWarning ) {
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> }} / > } / > ;
}
2018-05-20 01:37:33 +09:00
2018-01-02 22:24:52 +09:00
if ( hashtagWarning ) {
2022-04-29 07:24:31 +09:00
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." / > } / > ;
2018-01-02 22:24:52 +09:00
}
2018-05-20 01:37:33 +09:00
2018-03-30 02:08:34 +09:00
if ( directMessageWarning ) {
2018-05-20 01:37:33 +09:00
const message = (
< span >
2022-04-29 07:24:31 +09:00
< FormattedMessage id = 'compose_form.encryption_warning' defaultMessage = 'Posts on Mastodon are not end-to-end encrypted. Do not share any dangerous information over Mastodon.' / > < a href = '/terms' target = '_blank' > < FormattedMessage id = 'compose_form.direct_message_warning_learn_more' defaultMessage = 'Learn more' / > < / a >
2018-05-20 01:37:33 +09:00
< / s p a n >
) ;
return < Warning message = { message } / > ;
2018-03-30 02:08:34 +09:00
}
2017-04-24 07:38:37 +09:00
return null ;
} ;
WarningWrapper . propTypes = {
needsLockWarning : PropTypes . bool ,
2018-01-02 22:24:52 +09:00
hashtagWarning : PropTypes . bool ,
2018-03-30 02:08:34 +09:00
directMessageWarning : PropTypes . bool ,
2017-04-24 07:38:37 +09:00
} ;
export default connect ( mapStateToProps ) ( WarningWrapper ) ;