2017-07-18 11:14:43 -04:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2023-05-28 10:38:10 -04:00
import { connect } from 'react-redux' ;
2016-10-28 14:05:44 -04:00
import {
followAccount ,
2017-01-16 13:36:32 -05:00
unfollowAccount ,
blockAccount ,
2017-02-05 20:51:56 -05:00
unblockAccount ,
muteAccount ,
unmuteAccount ,
2023-11-15 06:01:51 -05:00
} from '../actions/accounts' ;
import { openModal } from '../actions/modal' ;
import { initMuteModal } from '../actions/mutes' ;
import Account from '../components/account' ;
import { makeGetAccount } from '../selectors' ;
2017-07-18 11:14:43 -04:00
const messages = defineMessages ( {
unfollowConfirm : { id : 'confirmations.unfollow.confirm' , defaultMessage : 'Unfollow' } ,
} ) ;
2016-10-27 15:59:56 -04:00
const makeMapStateToProps = ( ) => {
const getAccount = makeGetAccount ( ) ;
const mapStateToProps = ( state , props ) => ( {
account : getAccount ( state , props . id ) ,
} ) ;
return mapStateToProps ;
} ;
2017-07-18 11:14:43 -04:00
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
2016-10-28 14:05:44 -04:00
onFollow ( account ) {
2017-09-02 14:44:41 -04:00
if ( account . getIn ( [ 'relationship' , 'following' ] ) || account . getIn ( [ 'relationship' , 'requested' ] ) ) {
2024-03-22 12:24:04 -04:00
dispatch ( openModal ( {
modalType : 'CONFIRM' ,
modalProps : {
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' ) ) ) ,
} ,
} ) ) ;
2016-10-28 14:05:44 -04:00
} else {
dispatch ( followAccount ( account . get ( 'id' ) ) ) ;
}
2017-01-16 13:36:32 -05:00
} ,
onBlock ( account ) {
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
dispatch ( unblockAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( blockAccount ( account . get ( 'id' ) ) ) ;
}
2017-02-05 20:51:56 -05:00
} ,
onMute ( account ) {
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
dispatch ( unmuteAccount ( account . get ( 'id' ) ) ) ;
} else {
2017-11-14 21:56:41 -05:00
dispatch ( initMuteModal ( account ) ) ;
2017-02-05 20:51:56 -05:00
}
2017-05-20 11:31:47 -04:00
} ,
2017-07-18 11:14:43 -04:00
2017-11-14 21:56:41 -05:00
onMuteNotifications ( account , notifications ) {
dispatch ( muteAccount ( account . get ( 'id' ) , notifications ) ) ;
} ,
2016-10-27 15:59:56 -04:00
} ) ;
2017-07-18 11:14:43 -04:00
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Account ) ) ;