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.

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