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.

175 lines
7.8 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import DropdownMenuContainer from 'flavours/glitch/containers/dropdown_menu_container';
  5. import { NavLink } from 'react-router-dom';
  6. import { defineMessages, injectIntl, FormattedMessage, FormattedNumber } from 'react-intl';
  7. import { me, isStaff } from 'flavours/glitch/util/initial_state';
  8. import { profileLink, accountAdminLink } from 'flavours/glitch/util/backend_links';
  9. const messages = defineMessages({
  10. mention: { id: 'account.mention', defaultMessage: 'Mention @{name}' },
  11. direct: { id: 'account.direct', defaultMessage: 'Direct message @{name}' },
  12. edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
  13. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  14. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  15. unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
  16. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  17. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  18. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  19. report: { id: 'account.report', defaultMessage: 'Report @{name}' },
  20. share: { id: 'account.share', defaultMessage: 'Share @{name}\'s profile' },
  21. media: { id: 'account.media', defaultMessage: 'Media' },
  22. blockDomain: { id: 'account.block_domain', defaultMessage: 'Hide everything from {domain}' },
  23. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' },
  24. hideReblogs: { id: 'account.hide_reblogs', defaultMessage: 'Hide boosts from @{name}' },
  25. showReblogs: { id: 'account.show_reblogs', defaultMessage: 'Show boosts from @{name}' },
  26. endorse: { id: 'account.endorse', defaultMessage: 'Feature on profile' },
  27. unendorse: { id: 'account.unendorse', defaultMessage: 'Don\'t feature on profile' },
  28. add_or_remove_from_list: { id: 'account.add_or_remove_from_list', defaultMessage: 'Add or Remove from lists' },
  29. admin_account: { id: 'status.admin_account', defaultMessage: 'Open moderation interface for @{name}' },
  30. });
  31. @injectIntl
  32. export default class ActionBar extends React.PureComponent {
  33. static propTypes = {
  34. account: ImmutablePropTypes.map.isRequired,
  35. onFollow: PropTypes.func,
  36. onBlock: PropTypes.func.isRequired,
  37. onMention: PropTypes.func.isRequired,
  38. onDirect: PropTypes.func.isRequired,
  39. onReblogToggle: PropTypes.func.isRequired,
  40. onReport: PropTypes.func.isRequired,
  41. onMute: PropTypes.func.isRequired,
  42. onBlockDomain: PropTypes.func.isRequired,
  43. onUnblockDomain: PropTypes.func.isRequired,
  44. onEndorseToggle: PropTypes.func.isRequired,
  45. onAddToList: PropTypes.func.isRequired,
  46. intl: PropTypes.object.isRequired,
  47. };
  48. handleShare = () => {
  49. navigator.share({
  50. url: this.props.account.get('url'),
  51. });
  52. }
  53. isStatusesPageActive = (match, location) => {
  54. if (!match) {
  55. return false;
  56. }
  57. return !location.pathname.match(/\/(followers|following)\/?$/);
  58. }
  59. render () {
  60. const { account, intl } = this.props;
  61. let menu = [];
  62. let extraInfo = '';
  63. menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention });
  64. menu.push({ text: intl.formatMessage(messages.direct, { name: account.get('username') }), action: this.props.onDirect });
  65. if ('share' in navigator) {
  66. menu.push({ text: intl.formatMessage(messages.share, { name: account.get('username') }), action: this.handleShare });
  67. }
  68. menu.push(null);
  69. if (account.get('id') === me) {
  70. if (profileLink !== undefined) {
  71. menu.push({ text: intl.formatMessage(messages.edit_profile), href: profileLink });
  72. }
  73. } else {
  74. if (account.getIn(['relationship', 'following'])) {
  75. if (account.getIn(['relationship', 'showing_reblogs'])) {
  76. menu.push({ text: intl.formatMessage(messages.hideReblogs, { name: account.get('username') }), action: this.props.onReblogToggle });
  77. } else {
  78. menu.push({ text: intl.formatMessage(messages.showReblogs, { name: account.get('username') }), action: this.props.onReblogToggle });
  79. }
  80. menu.push({ text: intl.formatMessage(account.getIn(['relationship', 'endorsed']) ? messages.unendorse : messages.endorse), action: this.props.onEndorseToggle });
  81. menu.push({ text: intl.formatMessage(messages.add_or_remove_from_list), action: this.props.onAddToList });
  82. menu.push(null);
  83. }
  84. if (account.getIn(['relationship', 'muting'])) {
  85. menu.push({ text: intl.formatMessage(messages.unmute, { name: account.get('username') }), action: this.props.onMute });
  86. } else {
  87. menu.push({ text: intl.formatMessage(messages.mute, { name: account.get('username') }), action: this.props.onMute });
  88. }
  89. if (account.getIn(['relationship', 'blocking'])) {
  90. menu.push({ text: intl.formatMessage(messages.unblock, { name: account.get('username') }), action: this.props.onBlock });
  91. } else {
  92. menu.push({ text: intl.formatMessage(messages.block, { name: account.get('username') }), action: this.props.onBlock });
  93. }
  94. menu.push({ text: intl.formatMessage(messages.report, { name: account.get('username') }), action: this.props.onReport });
  95. }
  96. if (account.get('acct') !== account.get('username')) {
  97. const domain = account.get('acct').split('@')[1];
  98. extraInfo = (
  99. <div className='account__disclaimer'>
  100. <FormattedMessage
  101. id='account.disclaimer_full'
  102. defaultMessage="Information below may reflect the user's profile incompletely."
  103. />
  104. {' '}
  105. <a target='_blank' rel='noopener' href={account.get('url')}>
  106. <FormattedMessage id='account.view_full_profile' defaultMessage='View full profile' />
  107. </a>
  108. </div>
  109. );
  110. menu.push(null);
  111. if (account.getIn(['relationship', 'domain_blocking'])) {
  112. menu.push({ text: intl.formatMessage(messages.unblockDomain, { domain }), action: this.props.onUnblockDomain });
  113. } else {
  114. menu.push({ text: intl.formatMessage(messages.blockDomain, { domain }), action: this.props.onBlockDomain });
  115. }
  116. }
  117. if (account.get('id') !== me && isStaff && (accountAdminLink !== undefined)) {
  118. menu.push(null);
  119. menu.push({
  120. text: intl.formatMessage(messages.admin_account, { name: account.get('username') }),
  121. href: accountAdminLink(account.get('id')),
  122. });
  123. }
  124. return (
  125. <div>
  126. {extraInfo}
  127. <div className='account__action-bar'>
  128. <div className='account__action-bar-dropdown'>
  129. <DropdownMenuContainer items={menu} icon='bars' size={24} direction='right' />
  130. </div>
  131. <div className='account__action-bar-links'>
  132. <NavLink isActive={this.isStatusesPageActive} activeClassName='active' className='account__action-bar__tab' to={`/accounts/${account.get('id')}`}>
  133. <FormattedMessage id='account.posts' defaultMessage='Posts' />
  134. <strong><FormattedNumber value={account.get('statuses_count')} /></strong>
  135. </NavLink>
  136. <NavLink exact activeClassName='active' className='account__action-bar__tab' to={`/accounts/${account.get('id')}/following`}>
  137. <FormattedMessage id='account.follows' defaultMessage='Follows' />
  138. <strong><FormattedNumber value={account.get('following_count')} /></strong>
  139. </NavLink>
  140. <NavLink exact activeClassName='active' className='account__action-bar__tab' to={`/accounts/${account.get('id')}/followers`}>
  141. <FormattedMessage id='account.followers' defaultMessage='Followers' />
  142. <strong>{ account.get('followers_count') < 0 ? '-' : <FormattedNumber value={account.get('followers_count')} /> }</strong>
  143. </NavLink>
  144. </div>
  145. </div>
  146. </div>
  147. );
  148. }
  149. }