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

138 lines
5.4 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. const messages = defineMessages({
  8. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  9. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  10. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  11. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  12. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  13. replyAll: { id: 'status.replyAll', defaultMessage: 'Reply to thread' },
  14. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  15. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  16. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  17. open: { id: 'status.open', defaultMessage: 'Expand this status' },
  18. report: { id: 'status.report', defaultMessage: 'Report @{name}' }
  19. });
  20. class StatusActionBar extends React.PureComponent {
  21. constructor (props, context) {
  22. super(props, context);
  23. this.handleReplyClick = this.handleReplyClick.bind(this);
  24. this.handleFavouriteClick = this.handleFavouriteClick.bind(this);
  25. this.handleReblogClick = this.handleReblogClick.bind(this);
  26. this.handleDeleteClick = this.handleDeleteClick.bind(this);
  27. this.handleMentionClick = this.handleMentionClick.bind(this);
  28. this.handleMuteClick = this.handleMuteClick.bind(this);
  29. this.handleBlockClick = this.handleBlockClick.bind(this);
  30. this.handleOpen = this.handleOpen.bind(this);
  31. this.handleReport = this.handleReport.bind(this);
  32. }
  33. handleReplyClick () {
  34. this.props.onReply(this.props.status, this.context.router);
  35. }
  36. handleFavouriteClick () {
  37. this.props.onFavourite(this.props.status);
  38. }
  39. handleReblogClick (e) {
  40. this.props.onReblog(this.props.status, e);
  41. }
  42. handleDeleteClick () {
  43. this.props.onDelete(this.props.status);
  44. }
  45. handleMentionClick () {
  46. this.props.onMention(this.props.status.get('account'), this.context.router);
  47. }
  48. handleMuteClick () {
  49. this.props.onMute(this.props.status.get('account'));
  50. }
  51. handleBlockClick () {
  52. this.props.onBlock(this.props.status.get('account'));
  53. }
  54. handleOpen () {
  55. this.context.router.push(`/statuses/${this.props.status.get('id')}`);
  56. }
  57. handleReport () {
  58. this.props.onReport(this.props.status);
  59. this.context.router.push('/report');
  60. }
  61. render () {
  62. const { status, me, intl } = this.props;
  63. const reblog_disabled = status.get('visibility') === 'private' || status.get('visibility') === 'direct';
  64. let menu = [];
  65. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  66. menu.push(null);
  67. if (status.getIn(['account', 'id']) === me) {
  68. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  69. } else {
  70. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  71. menu.push(null);
  72. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  73. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  74. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  75. }
  76. let reblogIcon = 'retweet';
  77. if (status.get('visibility') === 'direct') reblogIcon = 'envelope';
  78. else if (status.get('visibility') === 'private') reblogIcon = 'lock';
  79. let reply_icon;
  80. let reply_title;
  81. if (status.get('in_reply_to_id', null) === null) {
  82. reply_icon = "reply";
  83. reply_title = intl.formatMessage(messages.reply);
  84. } else {
  85. reply_icon = "reply-all";
  86. reply_title = intl.formatMessage(messages.replyAll);
  87. }
  88. return (
  89. <div className='status__action-bar'>
  90. <div className='status__action-bar-button-wrapper'><IconButton title={reply_title} icon={reply_icon} onClick={this.handleReplyClick} /></div>
  91. <div className='status__action-bar-button-wrapper'><IconButton disabled={reblog_disabled} active={status.get('reblogged')} title={reblog_disabled ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} /></div>
  92. <div className='status__action-bar-button-wrapper'><IconButton animate={true} active={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} className='star-icon' /></div>
  93. <div className='status__action-bar-dropdown'>
  94. <DropdownMenu items={menu} icon='ellipsis-h' size={18} direction="right" ariaLabel="More"/>
  95. </div>
  96. </div>
  97. );
  98. }
  99. }
  100. StatusActionBar.contextTypes = {
  101. router: PropTypes.object
  102. };
  103. StatusActionBar.propTypes = {
  104. status: ImmutablePropTypes.map.isRequired,
  105. onReply: PropTypes.func,
  106. onFavourite: PropTypes.func,
  107. onReblog: PropTypes.func,
  108. onDelete: PropTypes.func,
  109. onMention: PropTypes.func,
  110. onMute: PropTypes.func,
  111. onBlock: PropTypes.func,
  112. onReport: PropTypes.func,
  113. me: PropTypes.number.isRequired,
  114. intl: PropTypes.object.isRequired
  115. };
  116. export default injectIntl(StatusActionBar);