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

153 lines
5.7 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import IconButton from './icon_button';
  5. import DropdownMenu from './dropdown_menu';
  6. import { defineMessages, injectIntl } from 'react-intl';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. const messages = defineMessages({
  9. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  10. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  11. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  12. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  13. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  14. replyAll: { id: 'status.replyAll', defaultMessage: 'Reply to thread' },
  15. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  16. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  17. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  18. open: { id: 'status.open', defaultMessage: 'Expand this status' },
  19. report: { id: 'status.report', defaultMessage: 'Report @{name}' },
  20. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  21. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  22. });
  23. class StatusActionBar extends ImmutablePureComponent {
  24. static contextTypes = {
  25. router: PropTypes.object,
  26. };
  27. static propTypes = {
  28. status: ImmutablePropTypes.map.isRequired,
  29. onReply: PropTypes.func,
  30. onFavourite: PropTypes.func,
  31. onReblog: PropTypes.func,
  32. onDelete: PropTypes.func,
  33. onMention: PropTypes.func,
  34. onMute: PropTypes.func,
  35. onBlock: PropTypes.func,
  36. onReport: PropTypes.func,
  37. onMuteConversation: PropTypes.func,
  38. me: PropTypes.number.isRequired,
  39. withDismiss: PropTypes.bool,
  40. intl: PropTypes.object.isRequired,
  41. };
  42. // Avoid checking props that are functions (and whose equality will always
  43. // evaluate to false. See react-immutable-pure-component for usage.
  44. updateOnProps = [
  45. 'status',
  46. 'me',
  47. 'withDismiss',
  48. ]
  49. handleReplyClick = () => {
  50. this.props.onReply(this.props.status, this.context.router);
  51. }
  52. handleFavouriteClick = () => {
  53. this.props.onFavourite(this.props.status);
  54. }
  55. handleReblogClick = (e) => {
  56. this.props.onReblog(this.props.status, e);
  57. }
  58. handleDeleteClick = () => {
  59. this.props.onDelete(this.props.status);
  60. }
  61. handleMentionClick = () => {
  62. this.props.onMention(this.props.status.get('account'), this.context.router);
  63. }
  64. handleMuteClick = () => {
  65. this.props.onMute(this.props.status.get('account'));
  66. }
  67. handleBlockClick = () => {
  68. this.props.onBlock(this.props.status.get('account'));
  69. }
  70. handleOpen = () => {
  71. this.context.router.push(`/statuses/${this.props.status.get('id')}`);
  72. }
  73. handleReport = () => {
  74. this.props.onReport(this.props.status);
  75. this.context.router.push('/report');
  76. }
  77. handleConversationMuteClick = () => {
  78. this.props.onMuteConversation(this.props.status);
  79. }
  80. render () {
  81. const { status, me, intl, withDismiss } = this.props;
  82. const reblogDisabled = status.get('visibility') === 'private' || status.get('visibility') === 'direct';
  83. const mutingConversation = status.get('muted');
  84. let menu = [];
  85. let reblogIcon = 'retweet';
  86. let replyIcon;
  87. let replyTitle;
  88. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  89. menu.push(null);
  90. if (withDismiss) {
  91. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  92. menu.push(null);
  93. }
  94. if (status.getIn(['account', 'id']) === me) {
  95. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  96. } else {
  97. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  98. menu.push(null);
  99. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  100. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  101. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  102. }
  103. if (status.get('visibility') === 'direct') {
  104. reblogIcon = 'envelope';
  105. } else if (status.get('visibility') === 'private') {
  106. reblogIcon = 'lock';
  107. }
  108. if (status.get('in_reply_to_id', null) === null) {
  109. replyIcon = 'reply';
  110. replyTitle = intl.formatMessage(messages.reply);
  111. } else {
  112. replyIcon = 'reply-all';
  113. replyTitle = intl.formatMessage(messages.replyAll);
  114. }
  115. return (
  116. <div className='status__action-bar'>
  117. <IconButton className='status__action-bar-button' title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} />
  118. <IconButton className='status__action-bar-button' disabled={reblogDisabled} active={status.get('reblogged')} title={reblogDisabled ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} />
  119. <IconButton className='status__action-bar-button star-icon' animate active={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} />
  120. <div className='status__action-bar-dropdown'>
  121. <DropdownMenu items={menu} icon='ellipsis-h' size={18} direction='right' ariaLabel='More' />
  122. </div>
  123. </div>
  124. );
  125. }
  126. }
  127. export default injectIntl(StatusActionBar);