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.

143 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 reblogDisabled = status.get('visibility') === 'private' || status.get('visibility') === 'direct';
  64. let menu = [];
  65. let reblogIcon = 'retweet';
  66. let replyIcon;
  67. let replyTitle;
  68. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  69. menu.push(null);
  70. if (status.getIn(['account', 'id']) === me) {
  71. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  72. } else {
  73. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  74. menu.push(null);
  75. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  76. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  77. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  78. }
  79. if (status.get('visibility') === 'direct') {
  80. reblogIcon = 'envelope';
  81. } else if (status.get('visibility') === 'private') {
  82. reblogIcon = 'lock';
  83. }
  84. if (status.get('in_reply_to_id', null) === null) {
  85. replyIcon = "reply";
  86. replyTitle = intl.formatMessage(messages.reply);
  87. } else {
  88. replyIcon = "reply-all";
  89. replyTitle = intl.formatMessage(messages.replyAll);
  90. }
  91. return (
  92. <div className='status__action-bar'>
  93. <div className='status__action-bar-button-wrapper'><IconButton title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} /></div>
  94. <div className='status__action-bar-button-wrapper'><IconButton disabled={reblogDisabled} active={status.get('reblogged')} title={reblogDisabled ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} /></div>
  95. <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>
  96. <div className='status__action-bar-dropdown'>
  97. <DropdownMenu items={menu} icon='ellipsis-h' size={18} direction="right" ariaLabel="More"/>
  98. </div>
  99. </div>
  100. );
  101. }
  102. }
  103. StatusActionBar.contextTypes = {
  104. router: PropTypes.object
  105. };
  106. StatusActionBar.propTypes = {
  107. status: ImmutablePropTypes.map.isRequired,
  108. onReply: PropTypes.func,
  109. onFavourite: PropTypes.func,
  110. onReblog: PropTypes.func,
  111. onDelete: PropTypes.func,
  112. onMention: PropTypes.func,
  113. onMute: PropTypes.func,
  114. onBlock: PropTypes.func,
  115. onReport: PropTypes.func,
  116. me: PropTypes.number.isRequired,
  117. intl: PropTypes.object.isRequired
  118. };
  119. export default injectIntl(StatusActionBar);