You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.2 KiB

  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import PropTypes from 'prop-types';
  3. import Avatar from './avatar';
  4. import DisplayName from './display_name';
  5. import Permalink from './permalink';
  6. import IconButton from './icon_button';
  7. import { defineMessages, injectIntl } from 'react-intl';
  8. const messages = defineMessages({
  9. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  10. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  11. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
  12. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  13. unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }
  14. });
  15. class Account extends React.PureComponent {
  16. constructor (props, context) {
  17. super(props, context);
  18. this.handleFollow = this.handleFollow.bind(this);
  19. this.handleBlock = this.handleBlock.bind(this);
  20. this.handleMute = this.handleMute.bind(this);
  21. }
  22. handleFollow () {
  23. this.props.onFollow(this.props.account);
  24. }
  25. handleBlock () {
  26. this.props.onBlock(this.props.account);
  27. }
  28. handleMute () {
  29. this.props.onMute(this.props.account);
  30. }
  31. render () {
  32. const { account, me, intl } = this.props;
  33. if (!account) {
  34. return <div />;
  35. }
  36. let buttons;
  37. if (account.get('id') !== me && account.get('relationship', null) !== null) {
  38. const following = account.getIn(['relationship', 'following']);
  39. const requested = account.getIn(['relationship', 'requested']);
  40. const blocking = account.getIn(['relationship', 'blocking']);
  41. const muting = account.getIn(['relationship', 'muting']);
  42. if (requested) {
  43. buttons = <IconButton disabled={true} icon='hourglass' title={intl.formatMessage(messages.requested)} />
  44. } else if (blocking) {
  45. buttons = <IconButton active={true} icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.handleBlock} />;
  46. } else if (muting) {
  47. buttons = <IconButton active={true} icon='volume-up' title={intl.formatMessage(messages.unmute, { name: account.get('username') })} onClick={this.handleMute} />;
  48. } else {
  49. buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
  50. }
  51. }
  52. return (
  53. <div className='account'>
  54. <div className='account__wrapper'>
  55. <Permalink key={account.get('id')} className='account__display-name' href={account.get('url')} to={`/accounts/${account.get('id')}`}>
  56. <div className='account__avatar-wrapper'><Avatar src={account.get('avatar')} staticSrc={account.get('avatar_static')} size={36} /></div>
  57. <DisplayName account={account} />
  58. </Permalink>
  59. <div className='account__relationship'>
  60. {buttons}
  61. </div>
  62. </div>
  63. </div>
  64. );
  65. }
  66. }
  67. Account.propTypes = {
  68. account: ImmutablePropTypes.map.isRequired,
  69. me: PropTypes.number.isRequired,
  70. onFollow: PropTypes.func.isRequired,
  71. onBlock: PropTypes.func.isRequired,
  72. onMute: PropTypes.func.isRequired,
  73. intl: PropTypes.object.isRequired
  74. }
  75. export default injectIntl(Account);