闭社主体 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.

133 lines
5.5 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
  5. import Link from 'react-router-dom/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. share: { id: 'account.share', defaultMessage: 'Share @{name}\'s profile' },
  18. media: { id: 'account.media', defaultMessage: 'Media' },
  19. blockDomain: { id: 'account.block_domain', defaultMessage: 'Hide everything from {domain}' },
  20. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' },
  21. });
  22. @injectIntl
  23. export default class ActionBar extends React.PureComponent {
  24. static propTypes = {
  25. account: ImmutablePropTypes.map.isRequired,
  26. me: PropTypes.number.isRequired,
  27. onFollow: PropTypes.func,
  28. onBlock: PropTypes.func.isRequired,
  29. onMention: PropTypes.func.isRequired,
  30. onReport: PropTypes.func.isRequired,
  31. onMute: PropTypes.func.isRequired,
  32. onBlockDomain: PropTypes.func.isRequired,
  33. onUnblockDomain: PropTypes.func.isRequired,
  34. intl: PropTypes.object.isRequired,
  35. };
  36. handleShare = () => {
  37. navigator.share({
  38. url: this.props.account.get('url'),
  39. });
  40. }
  41. render () {
  42. const { account, me, intl } = this.props;
  43. let menu = [];
  44. let extraInfo = '';
  45. menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention });
  46. if ('share' in navigator) {
  47. menu.push({ text: intl.formatMessage(messages.share, { name: account.get('username') }), action: this.handleShare });
  48. }
  49. menu.push(null);
  50. menu.push({ text: intl.formatMessage(messages.media), to: `/accounts/${account.get('id')}/media` });
  51. menu.push(null);
  52. if (account.get('id') === me) {
  53. menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' });
  54. } else {
  55. if (account.getIn(['relationship', 'muting'])) {
  56. menu.push({ text: intl.formatMessage(messages.unmute, { name: account.get('username') }), action: this.props.onMute });
  57. } else {
  58. menu.push({ text: intl.formatMessage(messages.mute, { name: account.get('username') }), action: this.props.onMute });
  59. }
  60. if (account.getIn(['relationship', 'blocking'])) {
  61. menu.push({ text: intl.formatMessage(messages.unblock, { name: account.get('username') }), action: this.props.onBlock });
  62. } else {
  63. menu.push({ text: intl.formatMessage(messages.block, { name: account.get('username') }), action: this.props.onBlock });
  64. }
  65. menu.push({ text: intl.formatMessage(messages.report, { name: account.get('username') }), action: this.props.onReport });
  66. }
  67. if (account.get('acct') !== account.get('username')) {
  68. const domain = account.get('acct').split('@')[1];
  69. extraInfo = (
  70. <div className='account__disclaimer'>
  71. <FormattedMessage
  72. id='account.disclaimer_full'
  73. defaultMessage="Information below may reflect the user's profile incompletely."
  74. />
  75. {' '}
  76. <a target='_blank' rel='noopener' href={account.get('url')}>
  77. <FormattedMessage id='account.view_full_profile' defaultMessage='View full profile' />
  78. </a>
  79. </div>
  80. );
  81. menu.push(null);
  82. if (account.getIn(['relationship', 'domain_blocking'])) {
  83. menu.push({ text: intl.formatMessage(messages.unblockDomain, { domain }), action: this.props.onUnblockDomain });
  84. } else {
  85. menu.push({ text: intl.formatMessage(messages.blockDomain, { domain }), action: this.props.onBlockDomain });
  86. }
  87. }
  88. return (
  89. <div>
  90. {extraInfo}
  91. <div className='account__action-bar'>
  92. <div className='account__action-bar-dropdown'>
  93. <DropdownMenuContainer items={menu} icon='bars' size={24} direction='right' />
  94. </div>
  95. <div className='account__action-bar-links'>
  96. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}`}>
  97. <span><FormattedMessage id='account.posts' defaultMessage='Posts' /></span>
  98. <strong><FormattedNumber value={account.get('statuses_count')} /></strong>
  99. </Link>
  100. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/following`}>
  101. <span><FormattedMessage id='account.follows' defaultMessage='Follows' /></span>
  102. <strong><FormattedNumber value={account.get('following_count')} /></strong>
  103. </Link>
  104. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/followers`}>
  105. <span><FormattedMessage id='account.followers' defaultMessage='Followers' /></span>
  106. <strong><FormattedNumber value={account.get('followers_count')} /></strong>
  107. </Link>
  108. </div>
  109. </div>
  110. </div>
  111. );
  112. }
  113. }