2019-04-20 15:28:03 -04:00
import { connect } from 'react-redux' ;
2019-05-10 05:27:59 -04:00
import { defineMessages , injectIntl } from 'react-intl' ;
2019-04-20 15:28:03 -04:00
import ComposeForm from '../components/compose_form' ;
import {
changeCompose ,
changeComposeSpoilerText ,
changeComposeSpoilerness ,
changeComposeVisibility ,
clearComposeSuggestions ,
fetchComposeSuggestions ,
insertEmojiCompose ,
selectComposeSuggestion ,
submitCompose ,
uploadCompose ,
} from 'flavours/glitch/actions/compose' ;
import {
openModal ,
} from 'flavours/glitch/actions/modal' ;
import { changeLocalSetting } from 'flavours/glitch/actions/local_settings' ;
import { privacyPreference } from 'flavours/glitch/util/privacy_preference' ;
const messages = defineMessages ( {
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' } ,
2019-08-20 05:28:17 -04:00
missingDescriptionEdit : { id : 'confirmations.missing_media_description.edit' ,
defaultMessage : 'Edit media' } ,
2019-04-20 15:28:03 -04:00
} ) ;
// State mapping.
function mapStateToProps ( state ) {
const spoilersAlwaysOn = state . getIn ( [ 'local_settings' , 'always_show_spoilers_field' ] ) ;
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' ] ) ) {
case 'copy' :
sideArmPrivacy = replyPrivacy ;
break ;
case 'restrict' :
sideArmPrivacy = sideArmRestrictedPrivacy ;
break ;
}
sideArmPrivacy = sideArmPrivacy || sideArmBasePrivacy ;
return {
advancedOptions : state . getIn ( [ 'compose' , 'advanced_options' ] ) ,
focusDate : state . getIn ( [ 'compose' , 'focusDate' ] ) ,
caretPosition : state . getIn ( [ 'compose' , 'caretPosition' ] ) ,
isSubmitting : state . getIn ( [ 'compose' , 'is_submitting' ] ) ,
2022-02-09 18:15:30 -05:00
isEditing : state . getIn ( [ 'compose' , 'id' ] ) !== null ,
2019-04-20 15:28:03 -04:00
isChangingUpload : state . getIn ( [ 'compose' , 'is_changing_upload' ] ) ,
isUploading : state . getIn ( [ 'compose' , 'is_uploading' ] ) ,
layout : state . getIn ( [ 'local_settings' , 'layout' ] ) ,
media : state . getIn ( [ 'compose' , 'media_attachments' ] ) ,
preselectDate : state . getIn ( [ 'compose' , 'preselectDate' ] ) ,
privacy : state . getIn ( [ 'compose' , 'privacy' ] ) ,
sideArm : sideArmPrivacy ,
sensitive : state . getIn ( [ 'compose' , 'sensitive' ] ) ,
showSearch : state . getIn ( [ 'search' , 'submitted' ] ) && ! state . getIn ( [ 'search' , 'hidden' ] ) ,
spoiler : spoilersAlwaysOn || state . getIn ( [ 'compose' , 'spoiler' ] ) ,
spoilerText : state . getIn ( [ 'compose' , 'spoiler_text' ] ) ,
suggestions : state . getIn ( [ 'compose' , 'suggestions' ] ) ,
text : state . getIn ( [ 'compose' , 'text' ] ) ,
anyMedia : state . getIn ( [ 'compose' , 'media_attachments' ] ) . size > 0 ,
spoilersAlwaysOn : spoilersAlwaysOn ,
mediaDescriptionConfirmation : state . getIn ( [ 'local_settings' , 'confirm_missing_media_description' ] ) ,
preselectOnReply : state . getIn ( [ 'local_settings' , 'preselect_on_reply' ] ) ,
2022-01-23 12:24:34 -05:00
isInReply : state . getIn ( [ 'compose' , 'in_reply_to' ] ) !== null ,
2019-04-20 15:28:03 -04:00
} ;
} ;
// Dispatch mapping.
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
2019-04-21 13:07:48 -04:00
onChange ( text ) {
2019-04-20 15:28:03 -04:00
dispatch ( changeCompose ( text ) ) ;
} ,
2019-04-21 13:07:48 -04:00
onSubmit ( routerHistory ) {
dispatch ( submitCompose ( routerHistory ) ) ;
2019-04-20 15:28:03 -04:00
} ,
2019-04-21 13:07:48 -04:00
2019-04-20 15:28:03 -04:00
onClearSuggestions ( ) {
dispatch ( clearComposeSuggestions ( ) ) ;
} ,
2019-04-21 13:07:48 -04:00
2019-04-20 15:28:03 -04:00
onFetchSuggestions ( token ) {
dispatch ( fetchComposeSuggestions ( token ) ) ;
} ,
2019-04-21 13:07:48 -04:00
2019-04-11 11:18:55 -04:00
onSuggestionSelected ( position , token , suggestion , path ) {
dispatch ( selectComposeSuggestion ( position , token , suggestion , path ) ) ;
2019-04-21 13:07:48 -04:00
} ,
onChangeSpoilerText ( text ) {
dispatch ( changeComposeSpoilerText ( text ) ) ;
} ,
onPaste ( files ) {
dispatch ( uploadCompose ( files ) ) ;
} ,
onPickEmoji ( position , emoji ) {
2019-04-20 15:28:03 -04:00
dispatch ( insertEmojiCompose ( position , emoji ) ) ;
} ,
2019-04-21 13:07:48 -04:00
onChangeSpoilerness ( ) {
dispatch ( changeComposeSpoilerness ( ) ) ;
} ,
onChangeVisibility ( value ) {
dispatch ( changeComposeVisibility ( value ) ) ;
} ,
2020-03-14 07:04:55 -04:00
onMediaDescriptionConfirm ( routerHistory , mediaId , overriddenVisibility = null ) {
2019-04-20 15:28:03 -04:00
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( messages . missingDescriptionMessage ) ,
confirm : intl . formatMessage ( messages . missingDescriptionConfirm ) ,
2020-03-14 07:04:55 -04:00
onConfirm : ( ) => {
if ( overriddenVisibility ) {
dispatch ( changeComposeVisibility ( overriddenVisibility ) ) ;
} ;
dispatch ( submitCompose ( routerHistory ) ) ;
} ,
2019-08-20 05:28:17 -04:00
secondary : intl . formatMessage ( messages . missingDescriptionEdit ) ,
onSecondary : ( ) => dispatch ( openModal ( 'FOCAL_POINT' , { id : mediaId } ) ) ,
2019-04-20 15:28:03 -04:00
onDoNotAsk : ( ) => dispatch ( changeLocalSetting ( [ 'confirm_missing_media_description' ] , false ) ) ,
} ) ) ;
} ,
2019-04-21 13:07:48 -04:00
2019-04-20 15:28:03 -04:00
} ) ;
2019-05-10 05:27:59 -04:00
export default injectIntl ( connect ( mapStateToProps , mapDispatchToProps ) ( ComposeForm ) ) ;