2020-03-02 17:26:25 -05:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl'
2019-07-02 03:10:25 -04:00
import {
followAccount ,
unfollowAccount ,
blockAccount ,
unblockAccount ,
muteAccount ,
unmuteAccount ,
2020-03-02 17:26:25 -05:00
} from '../actions/accounts'
import { openModal } from '../actions/modal'
import { initMuteModal } from '../actions/mutes'
import { unfollowModal } from '../initial_state'
import { makeGetAccount } from '../selectors'
import Account from '../components/account'
2019-07-02 03:10:25 -04:00
const messages = defineMessages ( {
unfollowConfirm : { id : 'confirmations.unfollow.confirm' , defaultMessage : 'Unfollow' } ,
2020-03-02 17:26:25 -05:00
} )
2019-07-02 03:10:25 -04:00
const makeMapStateToProps = ( ) => {
2020-03-02 17:26:25 -05:00
const getAccount = makeGetAccount ( )
2019-07-02 03:10:25 -04:00
const mapStateToProps = ( state , props ) => ( {
account : getAccount ( state , props . id ) ,
2020-03-02 17:26:25 -05:00
} )
2019-07-02 03:10:25 -04:00
2020-03-02 17:26:25 -05:00
return mapStateToProps
}
2019-07-02 03:10:25 -04:00
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
onFollow ( account ) {
if ( account . getIn ( [ 'relationship' , 'following' ] ) || account . getIn ( [ 'relationship' , 'requested' ] ) ) {
if ( 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' ) ) ) ,
2020-03-02 17:26:25 -05:00
} ) )
2019-07-02 03:10:25 -04:00
} else {
2020-03-02 17:26:25 -05:00
dispatch ( unfollowAccount ( account . get ( 'id' ) ) )
2019-07-02 03:10:25 -04:00
}
} else {
2020-03-02 17:26:25 -05:00
dispatch ( followAccount ( account . get ( 'id' ) ) )
2019-07-02 03:10:25 -04:00
}
} ,
onBlock ( account ) {
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
2020-03-02 17:26:25 -05:00
dispatch ( unblockAccount ( account . get ( 'id' ) ) )
2019-07-02 03:10:25 -04:00
} else {
2020-03-02 17:26:25 -05:00
dispatch ( blockAccount ( account . get ( 'id' ) ) )
2019-07-02 03:10:25 -04:00
}
} ,
onMute ( account ) {
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
2020-03-02 17:26:25 -05:00
dispatch ( unmuteAccount ( account . get ( 'id' ) ) )
2019-07-02 03:10:25 -04:00
} else {
2020-03-02 17:26:25 -05:00
dispatch ( initMuteModal ( account ) )
2019-07-02 03:10:25 -04:00
}
} ,
onMuteNotifications ( account , notifications ) {
2020-03-02 17:26:25 -05:00
dispatch ( muteAccount ( account . get ( 'id' ) , notifications ) )
2019-07-02 03:10:25 -04:00
} ,
2020-03-02 17:26:25 -05:00
} )
2019-07-02 03:10:25 -04:00
2020-03-02 17:26:25 -05:00
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Account ) )