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

108 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-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. 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. @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. render () {
  37. const { account, me, intl } = this.props;
  38. let menu = [];
  39. let extraInfo = '';
  40. menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention });
  41. menu.push(null);
  42. menu.push({ text: intl.formatMessage(messages.media), to: `/accounts/${account.get('id')}/media` });
  43. menu.push(null);
  44. if (account.get('id') === me) {
  45. menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' });
  46. } else {
  47. if (account.getIn(['relationship', 'muting'])) {
  48. menu.push({ text: intl.formatMessage(messages.unmute, { name: account.get('username') }), action: this.props.onMute });
  49. } else {
  50. menu.push({ text: intl.formatMessage(messages.mute, { name: account.get('username') }), action: this.props.onMute });
  51. }
  52. if (account.getIn(['relationship', 'blocking'])) {
  53. menu.push({ text: intl.formatMessage(messages.unblock, { name: account.get('username') }), action: this.props.onBlock });
  54. } else {
  55. menu.push({ text: intl.formatMessage(messages.block, { name: account.get('username') }), action: this.props.onBlock });
  56. }
  57. menu.push({ text: intl.formatMessage(messages.report, { name: account.get('username') }), action: this.props.onReport });
  58. }
  59. if (account.get('acct') !== account.get('username')) {
  60. const domain = account.get('acct').split('@')[1];
  61. extraInfo = <abbr title={intl.formatMessage(messages.disclaimer)}>*</abbr>;
  62. menu.push(null);
  63. if (account.getIn(['relationship', 'domain_blocking'])) {
  64. menu.push({ text: intl.formatMessage(messages.unblockDomain, { domain }), action: this.props.onUnblockDomain });
  65. } else {
  66. menu.push({ text: intl.formatMessage(messages.blockDomain, { domain }), action: this.props.onBlockDomain });
  67. }
  68. }
  69. return (
  70. <div className='account__action-bar'>
  71. <div className='account__action-bar-dropdown'>
  72. <DropdownMenu items={menu} icon='bars' size={24} direction='right' />
  73. </div>
  74. <div className='account__action-bar-links'>
  75. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}`}>
  76. <span><FormattedMessage id='account.posts' defaultMessage='Posts' /></span>
  77. <strong><FormattedNumber value={account.get('statuses_count')} /> {extraInfo}</strong>
  78. </Link>
  79. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/following`}>
  80. <span><FormattedMessage id='account.follows' defaultMessage='Follows' /></span>
  81. <strong><FormattedNumber value={account.get('following_count')} /> {extraInfo}</strong>
  82. </Link>
  83. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/followers`}>
  84. <span><FormattedMessage id='account.followers' defaultMessage='Followers' /></span>
  85. <strong><FormattedNumber value={account.get('followers_count')} /> {extraInfo}</strong>
  86. </Link>
  87. </div>
  88. </div>
  89. );
  90. }
  91. }