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.

160 lines
6.1 KiB

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