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