import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import Avatar from './avatar'; import DisplayName from './display_name'; import Permalink from './permalink'; import IconButton from './icon_button'; import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; 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}' }, }); class Account extends ImmutablePureComponent { static propTypes = { account: ImmutablePropTypes.map.isRequired, me: PropTypes.number.isRequired, onFollow: PropTypes.func.isRequired, onBlock: PropTypes.func.isRequired, onMute: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; constructor (props, context) { super(props, context); this.handleFollow = this.handleFollow.bind(this); this.handleBlock = this.handleBlock.bind(this); this.handleMute = this.handleMute.bind(this); } handleFollow () { this.props.onFollow(this.props.account); } handleBlock () { this.props.onBlock(this.props.account); } handleMute () { this.props.onMute(this.props.account); } render () { const { account, me, intl } = this.props; if (!account) { return
; } 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 { buttons = ; } } return (
{buttons}
); } } export default injectIntl(Account);