2019-05-10 04:27:59 -05:00
import { defineMessages , injectIntl } from 'react-intl' ;
2023-05-28 09:38:10 -05:00
import { connect } from 'react-redux' ;
2023-11-15 05:01:51 -06:00
import { privacyPreference } from 'flavours/glitch/utils/privacy_preference' ;
2019-04-20 14:28:03 -05:00
import {
changeCompose ,
2023-11-15 05:01:51 -06:00
submitCompose ,
clearComposeSuggestions ,
fetchComposeSuggestions ,
selectComposeSuggestion ,
2019-04-20 14:28:03 -05:00
changeComposeSpoilerText ,
changeComposeSpoilerness ,
changeComposeVisibility ,
insertEmojiCompose ,
uploadCompose ,
2023-11-15 05:01:51 -06:00
} from '../../../actions/compose' ;
import { changeLocalSetting } from '../../../actions/local_settings' ;
2019-04-20 14:28:03 -05:00
import {
openModal ,
2023-11-15 05:01:51 -06:00
} from '../../../actions/modal' ;
2023-05-28 09:38:10 -05:00
import ComposeForm from '../components/compose_form' ;
2019-04-20 14:28:03 -05:00
const messages = defineMessages ( {
2023-02-04 04:09:05 -06:00
missingDescriptionMessage : {
id : 'confirmations.missing_media_description.message' ,
defaultMessage : 'At least one media attachment is lacking a description. Consider describing all media attachments for the visually impaired before sending your toot.' ,
} ,
missingDescriptionConfirm : {
id : 'confirmations.missing_media_description.confirm' ,
defaultMessage : 'Send anyway' ,
} ,
missingDescriptionEdit : {
id : 'confirmations.missing_media_description.edit' ,
defaultMessage : 'Edit media' ,
} ,
2019-04-20 14:28:03 -05:00
} ) ;
2023-12-18 06:20:08 -06:00
const sideArmPrivacy = state => {
2019-04-20 14:28:03 -05:00
const inReplyTo = state . getIn ( [ 'compose' , 'in_reply_to' ] ) ;
const replyPrivacy = inReplyTo ? state . getIn ( [ 'statuses' , inReplyTo , 'visibility' ] ) : null ;
const sideArmBasePrivacy = state . getIn ( [ 'local_settings' , 'side_arm' ] ) ;
const sideArmRestrictedPrivacy = replyPrivacy ? privacyPreference ( replyPrivacy , sideArmBasePrivacy ) : null ;
let sideArmPrivacy = null ;
switch ( state . getIn ( [ 'local_settings' , 'side_arm_reply_mode' ] ) ) {
2023-02-03 13:52:07 -06:00
case 'copy' :
sideArmPrivacy = replyPrivacy ;
break ;
case 'restrict' :
sideArmPrivacy = sideArmRestrictedPrivacy ;
break ;
2019-04-20 14:28:03 -05:00
}
2023-12-18 06:20:08 -06:00
return sideArmPrivacy || sideArmBasePrivacy ;
} ;
const mapStateToProps = state => ( {
text : state . getIn ( [ 'compose' , 'text' ] ) ,
suggestions : state . getIn ( [ 'compose' , 'suggestions' ] ) ,
spoiler : state . getIn ( [ 'local_settings' , 'always_show_spoilers_field' ] ) || state . getIn ( [ 'compose' , 'spoiler' ] ) ,
spoilerText : state . getIn ( [ 'compose' , 'spoiler_text' ] ) ,
privacy : state . getIn ( [ 'compose' , 'privacy' ] ) ,
focusDate : state . getIn ( [ 'compose' , 'focusDate' ] ) ,
caretPosition : state . getIn ( [ 'compose' , 'caretPosition' ] ) ,
preselectDate : state . getIn ( [ 'compose' , 'preselectDate' ] ) ,
isSubmitting : state . getIn ( [ 'compose' , 'is_submitting' ] ) ,
isEditing : state . getIn ( [ 'compose' , 'id' ] ) !== null ,
isChangingUpload : state . getIn ( [ 'compose' , 'is_changing_upload' ] ) ,
isUploading : state . getIn ( [ 'compose' , 'is_uploading' ] ) ,
anyMedia : state . getIn ( [ 'compose' , 'media_attachments' ] ) . size > 0 ,
isInReply : state . getIn ( [ 'compose' , 'in_reply_to' ] ) !== null ,
lang : state . getIn ( [ 'compose' , 'language' ] ) ,
advancedOptions : state . getIn ( [ 'compose' , 'advanced_options' ] ) ,
media : state . getIn ( [ 'compose' , 'media_attachments' ] ) ,
sideArm : sideArmPrivacy ( state ) ,
sensitive : state . getIn ( [ 'compose' , 'sensitive' ] ) ,
showSearch : state . getIn ( [ 'search' , 'submitted' ] ) && ! state . getIn ( [ 'search' , 'hidden' ] ) ,
spoilersAlwaysOn : state . getIn ( [ 'local_settings' , 'always_show_spoilers_field' ] ) ,
mediaDescriptionConfirmation : state . getIn ( [ 'local_settings' , 'confirm_missing_media_description' ] ) ,
preselectOnReply : state . getIn ( [ 'local_settings' , 'preselect_on_reply' ] ) ,
} ) ;
2019-04-20 14:28:03 -05:00
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
2019-04-21 12:07:48 -05:00
2023-12-18 06:20:08 -06:00
onChange ( text ) {
2019-04-20 14:28:03 -05:00
dispatch ( changeCompose ( text ) ) ;
} ,
2019-04-21 12:07:48 -05:00
2023-12-18 06:20:08 -06:00
onSubmit ( router ) {
dispatch ( submitCompose ( router ) ) ;
2019-04-20 14:28:03 -05:00
} ,
2019-04-21 12:07:48 -05:00
2023-12-18 06:20:08 -06:00
onClearSuggestions ( ) {
2019-04-20 14:28:03 -05:00
dispatch ( clearComposeSuggestions ( ) ) ;
} ,
2019-04-21 12:07:48 -05:00
2023-12-18 06:20:08 -06:00
onFetchSuggestions ( token ) {
2019-04-20 14:28:03 -05:00
dispatch ( fetchComposeSuggestions ( token ) ) ;
} ,
2019-04-21 12:07:48 -05:00
2023-12-18 06:20:08 -06:00
onSuggestionSelected ( position , token , suggestion , path ) {
2019-04-11 10:18:55 -05:00
dispatch ( selectComposeSuggestion ( position , token , suggestion , path ) ) ;
2019-04-21 12:07:48 -05:00
} ,
2023-12-18 06:20:08 -06:00
onChangeSpoilerText ( text ) {
2019-04-21 12:07:48 -05:00
dispatch ( changeComposeSpoilerText ( text ) ) ;
} ,
2023-12-18 06:20:08 -06:00
onPaste ( files ) {
2019-04-21 12:07:48 -05:00
dispatch ( uploadCompose ( files ) ) ;
} ,
2023-12-18 06:20:08 -06:00
onPickEmoji ( position , emoji ) {
2019-04-20 14:28:03 -05:00
dispatch ( insertEmojiCompose ( position , emoji ) ) ;
} ,
2019-04-21 12:07:48 -05:00
onChangeSpoilerness ( ) {
dispatch ( changeComposeSpoilerness ( ) ) ;
} ,
onChangeVisibility ( value ) {
dispatch ( changeComposeVisibility ( value ) ) ;
} ,
2020-03-14 06:04:55 -05:00
onMediaDescriptionConfirm ( routerHistory , mediaId , overriddenVisibility = null ) {
2023-05-25 08:42:37 -05:00
dispatch ( openModal ( {
modalType : 'CONFIRM' ,
modalProps : {
message : intl . formatMessage ( messages . missingDescriptionMessage ) ,
confirm : intl . formatMessage ( messages . missingDescriptionConfirm ) ,
onConfirm : ( ) => {
if ( overriddenVisibility ) {
dispatch ( changeComposeVisibility ( overriddenVisibility ) ) ;
}
dispatch ( submitCompose ( routerHistory ) ) ;
} ,
secondary : intl . formatMessage ( messages . missingDescriptionEdit ) ,
onSecondary : ( ) => dispatch ( openModal ( {
modalType : 'FOCAL_POINT' ,
modalProps : { id : mediaId } ,
} ) ) ,
onDoNotAsk : ( ) => dispatch ( changeLocalSetting ( [ 'confirm_missing_media_description' ] , false ) ) ,
2020-03-14 06:04:55 -05:00
} ,
2019-04-20 14:28:03 -05:00
} ) ) ;
} ,
2019-04-21 12:07:48 -05:00
2019-04-20 14:28:03 -05:00
} ) ;
2019-05-10 04:27:59 -05:00
export default injectIntl ( connect ( mapStateToProps , mapDispatchToProps ) ( ComposeForm ) ) ;