import React from 'react'; import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import SoapboxPropTypes from 'soapbox/utils/soapbox_prop_types'; import { connect } from 'react-redux'; import { makeGetAccount } from 'soapbox/selectors'; import Avatar from 'soapbox/components/avatar'; import DisplayName from 'soapbox/components/display_name'; import Permalink from 'soapbox/components/permalink'; import RelativeTimestamp from 'soapbox/components/relative_timestamp'; import IconButton from 'soapbox/components/icon_button'; import { FormattedMessage, injectIntl, defineMessages } from 'react-intl'; import { getSettings } from 'soapbox/actions/settings'; import { shortNumberFormat } from 'soapbox/utils/numbers'; import { followAccount, unfollowAccount, blockAccount, unblockAccount, unmuteAccount } from 'soapbox/actions/accounts'; import { openModal } from 'soapbox/actions/modal'; import { initMuteModal } from 'soapbox/actions/mutes'; const messages = defineMessages({ follow: { id: 'account.follow', defaultMessage: 'Follow' }, unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' }, requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' }, unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' }, unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }, }); const makeMapStateToProps = () => { const getAccount = makeGetAccount(); const mapStateToProps = (state, { id }) => ({ account: getAccount(state, id), autoPlayGif: getSettings(state).get('autoPlayGif'), me: state.get('me'), }); return mapStateToProps; }; const mapDispatchToProps = (dispatch, { intl }) => ({ onFollow(account) { dispatch((_, getState) => { const unfollowModal = getSettings(getState()).get('unfollowModal'); if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { if (unfollowModal) { dispatch(openModal('CONFIRM', { message: @{account.get('acct')} }} />, confirm: intl.formatMessage(messages.unfollowConfirm), onConfirm: () => dispatch(unfollowAccount(account.get('id'))), })); } else { dispatch(unfollowAccount(account.get('id'))); } } else { dispatch(followAccount(account.get('id'))); } }); }, onBlock(account) { if (account.getIn(['relationship', 'blocking'])) { dispatch(unblockAccount(account.get('id'))); } else { dispatch(blockAccount(account.get('id'))); } }, onMute(account) { if (account.getIn(['relationship', 'muting'])) { dispatch(unmuteAccount(account.get('id'))); } else { dispatch(initMuteModal(account)); } }, }); export default @injectIntl @connect(makeMapStateToProps, mapDispatchToProps) class AccountCard extends ImmutablePureComponent { static propTypes = { account: ImmutablePropTypes.map.isRequired, intl: PropTypes.object.isRequired, onFollow: PropTypes.func.isRequired, onBlock: PropTypes.func.isRequired, onMute: PropTypes.func.isRequired, autoPlayGif: PropTypes.bool, me: SoapboxPropTypes.me, }; handleFollow = () => { this.props.onFollow(this.props.account); } handleBlock = () => { this.props.onBlock(this.props.account); } handleMute = () => { this.props.onMute(this.props.account); } render() { const { account, intl, me, autoPlayGif } = this.props; let buttons; if (account.get('id') !== me && account.get('relationship', null) !== null) { const following = account.getIn(['relationship', 'following']); const requested = account.getIn(['relationship', 'requested']); const blocking = account.getIn(['relationship', 'blocking']); const muting = account.getIn(['relationship', 'muting']); if (requested) { buttons = ; } else if (blocking) { buttons = ; } else if (muting) { buttons = ; } else if (!account.get('moved') || following) { buttons = ; } } return (
{buttons}
{account.get('note').length > 0 && account.get('note') !== '

' && (
)}
{shortNumberFormat(account.get('statuses_count'))}
{shortNumberFormat(account.get('followers_count'))}
{account.get('last_status_at') === null ? : }
); } }