2017-07-19 01:14:43 +10:00
import React from 'react' ;
2016-11-21 05:39:18 +11:00
import { connect } from 'react-redux' ;
2017-07-19 01:14:43 +10:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2016-11-21 05:39:18 +11:00
import { makeGetAccount } from '../selectors' ;
import Account from '../components/account' ;
2016-10-29 05:05:44 +11:00
import {
followAccount ,
2017-01-17 05:36:32 +11:00
unfollowAccount ,
blockAccount ,
2017-02-06 12:51:56 +11:00
unblockAccount ,
muteAccount ,
unmuteAccount ,
2016-11-21 05:39:18 +11:00
} from '../actions/accounts' ;
2017-07-19 01:14:43 +10:00
import { openModal } from '../actions/modal' ;
const messages = defineMessages ( {
unfollowConfirm : { id : 'confirmations.unfollow.confirm' , defaultMessage : 'Unfollow' } ,
} ) ;
2016-10-28 06:59:56 +11:00
const makeMapStateToProps = ( ) => {
const getAccount = makeGetAccount ( ) ;
const mapStateToProps = ( state , props ) => ( {
account : getAccount ( state , props . id ) ,
2017-05-21 01:31:47 +10:00
me : state . getIn ( [ 'meta' , 'me' ] ) ,
2017-07-19 01:14:43 +10:00
unfollowModal : state . getIn ( [ 'meta' , 'unfollow_modal' ] ) ,
2016-10-28 06:59:56 +11:00
} ) ;
return mapStateToProps ;
} ;
2017-07-19 01:14:43 +10:00
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
2016-10-29 05:05:44 +11:00
onFollow ( account ) {
if ( account . getIn ( [ 'relationship' , 'following' ] ) ) {
2017-07-19 01:14:43 +10:00
if ( this . unfollowModal ) {
dispatch ( openModal ( 'CONFIRM' , {
message : < FormattedMessage id = 'confirmations.unfollow.message' defaultMessage = 'Are you sure you want to unfollow {name}?' values = { { name : < strong > @ { account . get ( 'acct' ) } < /strong> }} / > ,
confirm : intl . formatMessage ( messages . unfollowConfirm ) ,
onConfirm : ( ) => dispatch ( unfollowAccount ( account . get ( 'id' ) ) ) ,
} ) ) ;
} else {
dispatch ( unfollowAccount ( account . get ( 'id' ) ) ) ;
}
2016-10-29 05:05:44 +11:00
} else {
dispatch ( followAccount ( account . get ( 'id' ) ) ) ;
}
2017-01-17 05:36:32 +11:00
} ,
onBlock ( account ) {
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
dispatch ( unblockAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( blockAccount ( account . get ( 'id' ) ) ) ;
}
2017-02-06 12:51:56 +11:00
} ,
onMute ( account ) {
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
dispatch ( unmuteAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( muteAccount ( account . get ( 'id' ) ) ) ;
}
2017-05-21 01:31:47 +10:00
} ,
2017-07-19 01:14:43 +10:00
2016-10-28 06:59:56 +11:00
} ) ;
2017-07-19 01:14:43 +10:00
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Account ) ) ;