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.

85 lines
3.1 KiB

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