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

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