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.

137 lines
5.3 KiB

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