闭社主体 forked from https://github.com/tootsuite/mastodon
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.

109 lines
4.9 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import DropdownMenu from '../../../components/dropdown_menu';
  5. import Link from 'react-router/lib/Link';
  6. import { defineMessages, injectIntl, FormattedMessage, FormattedNumber } from 'react-intl';
  7. const messages = defineMessages({
  8. mention: { id: 'account.mention', defaultMessage: 'Mention @{name}' },
  9. edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
  10. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  11. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  12. unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
  13. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  14. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  15. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  16. report: { id: 'account.report', defaultMessage: 'Report @{name}' },
  17. media: { id: 'account.media', defaultMessage: 'Media' },
  18. disclaimer: { id: 'account.disclaimer', defaultMessage: 'This user is from another instance. This number may be larger.' },
  19. blockDomain: { id: 'account.block_domain', defaultMessage: 'Hide everything from {domain}' },
  20. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' },
  21. });
  22. class ActionBar extends React.PureComponent {
  23. static propTypes = {
  24. account: ImmutablePropTypes.map.isRequired,
  25. me: PropTypes.number.isRequired,
  26. onFollow: PropTypes.func,
  27. onBlock: PropTypes.func.isRequired,
  28. onMention: PropTypes.func.isRequired,
  29. onReport: PropTypes.func.isRequired,
  30. onMute: PropTypes.func.isRequired,
  31. onBlockDomain: PropTypes.func.isRequired,
  32. onUnblockDomain: PropTypes.func.isRequired,
  33. intl: PropTypes.object.isRequired,
  34. };
  35. render () {
  36. const { account, me, intl } = this.props;
  37. let menu = [];
  38. let extraInfo = '';
  39. menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention });
  40. menu.push(null);
  41. menu.push({ text: intl.formatMessage(messages.media), to: `/accounts/${account.get('id')}/media` });
  42. menu.push(null);
  43. if (account.get('id') === me) {
  44. menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' });
  45. } else {
  46. if (account.getIn(['relationship', 'muting'])) {
  47. menu.push({ text: intl.formatMessage(messages.unmute, { name: account.get('username') }), action: this.props.onMute });
  48. } else {
  49. menu.push({ text: intl.formatMessage(messages.mute, { name: account.get('username') }), action: this.props.onMute });
  50. }
  51. if (account.getIn(['relationship', 'blocking'])) {
  52. menu.push({ text: intl.formatMessage(messages.unblock, { name: account.get('username') }), action: this.props.onBlock });
  53. } else {
  54. menu.push({ text: intl.formatMessage(messages.block, { name: account.get('username') }), action: this.props.onBlock });
  55. }
  56. menu.push({ text: intl.formatMessage(messages.report, { name: account.get('username') }), action: this.props.onReport });
  57. }
  58. if (account.get('acct') !== account.get('username')) {
  59. const domain = account.get('acct').split('@')[1];
  60. extraInfo = <abbr title={intl.formatMessage(messages.disclaimer)}>*</abbr>;
  61. menu.push(null);
  62. if (account.getIn(['relationship', 'domain_blocking'])) {
  63. menu.push({ text: intl.formatMessage(messages.unblockDomain, { domain }), action: this.props.onUnblockDomain });
  64. } else {
  65. menu.push({ text: intl.formatMessage(messages.blockDomain, { domain }), action: this.props.onBlockDomain });
  66. }
  67. }
  68. return (
  69. <div className='account__action-bar'>
  70. <div className='account__action-bar-dropdown'>
  71. <DropdownMenu items={menu} icon='bars' size={24} direction='right' />
  72. </div>
  73. <div className='account__action-bar-links'>
  74. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}`}>
  75. <span><FormattedMessage id='account.posts' defaultMessage='Posts' /></span>
  76. <strong><FormattedNumber value={account.get('statuses_count')} /> {extraInfo}</strong>
  77. </Link>
  78. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/following`}>
  79. <span><FormattedMessage id='account.follows' defaultMessage='Follows' /></span>
  80. <strong><FormattedNumber value={account.get('following_count')} /> {extraInfo}</strong>
  81. </Link>
  82. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/followers`}>
  83. <span><FormattedMessage id='account.followers' defaultMessage='Followers' /></span>
  84. <strong><FormattedNumber value={account.get('followers_count')} /> {extraInfo}</strong>
  85. </Link>
  86. </div>
  87. </div>
  88. );
  89. }
  90. }
  91. export default injectIntl(ActionBar);