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.

188 lines
7.1 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 DropdownMenuContainer from '../containers/dropdown_menu_container';
  6. import { defineMessages, injectIntl } from 'react-intl';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. const messages = defineMessages({
  9. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  10. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  11. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  12. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  13. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  14. share: { id: 'status.share', defaultMessage: 'Share' },
  15. replyAll: { id: 'status.replyAll', defaultMessage: 'Reply to thread' },
  16. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  17. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  18. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  19. open: { id: 'status.open', defaultMessage: 'Expand this status' },
  20. report: { id: 'status.report', defaultMessage: 'Report @{name}' },
  21. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  22. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  23. pin: { id: 'status.pin', defaultMessage: 'Pin on profile' },
  24. unpin: { id: 'status.unpin', defaultMessage: 'Unpin from profile' },
  25. embed: { id: 'status.embed', defaultMessage: 'Embed' },
  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. onReply: PropTypes.func,
  35. onFavourite: PropTypes.func,
  36. onReblog: PropTypes.func,
  37. onDelete: PropTypes.func,
  38. onMention: PropTypes.func,
  39. onMute: PropTypes.func,
  40. onBlock: PropTypes.func,
  41. onReport: PropTypes.func,
  42. onEmbed: PropTypes.func,
  43. onMuteConversation: PropTypes.func,
  44. onPin: 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. handleShareClick = () => {
  60. navigator.share({
  61. text: this.props.status.get('search_index'),
  62. url: this.props.status.get('url'),
  63. });
  64. }
  65. handleFavouriteClick = () => {
  66. this.props.onFavourite(this.props.status);
  67. }
  68. handleReblogClick = (e) => {
  69. this.props.onReblog(this.props.status, e);
  70. }
  71. handleDeleteClick = () => {
  72. this.props.onDelete(this.props.status);
  73. }
  74. handlePinClick = () => {
  75. this.props.onPin(this.props.status);
  76. }
  77. handleMentionClick = () => {
  78. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  79. }
  80. handleMuteClick = () => {
  81. this.props.onMute(this.props.status.get('account'));
  82. }
  83. handleBlockClick = () => {
  84. this.props.onBlock(this.props.status.get('account'));
  85. }
  86. handleOpen = () => {
  87. this.context.router.history.push(`/statuses/${this.props.status.get('id')}`);
  88. }
  89. handleEmbed = () => {
  90. this.props.onEmbed(this.props.status);
  91. }
  92. handleReport = () => {
  93. this.props.onReport(this.props.status);
  94. }
  95. handleConversationMuteClick = () => {
  96. this.props.onMuteConversation(this.props.status);
  97. }
  98. render () {
  99. const { status, me, intl, withDismiss } = this.props;
  100. const mutingConversation = status.get('muted');
  101. const anonymousAccess = !me;
  102. const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
  103. let menu = [];
  104. let reblogIcon = 'retweet';
  105. let replyIcon;
  106. let replyTitle;
  107. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  108. if (publicStatus) {
  109. menu.push({ text: intl.formatMessage(messages.embed), action: this.handleEmbed });
  110. }
  111. menu.push(null);
  112. if (status.getIn(['account', 'id']) === me || withDismiss) {
  113. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  114. menu.push(null);
  115. }
  116. if (status.getIn(['account', 'id']) === me) {
  117. if (publicStatus) {
  118. menu.push({ text: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), action: this.handlePinClick });
  119. }
  120. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  121. } else {
  122. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  123. menu.push(null);
  124. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  125. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  126. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  127. }
  128. if (status.get('visibility') === 'direct') {
  129. reblogIcon = 'envelope';
  130. } else if (status.get('visibility') === 'private') {
  131. reblogIcon = 'lock';
  132. }
  133. if (status.get('in_reply_to_id', null) === null) {
  134. replyIcon = 'reply';
  135. replyTitle = intl.formatMessage(messages.reply);
  136. } else {
  137. replyIcon = 'reply-all';
  138. replyTitle = intl.formatMessage(messages.replyAll);
  139. }
  140. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  141. <IconButton className='status__action-bar-button' title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShareClick} />
  142. );
  143. return (
  144. <div className='status__action-bar'>
  145. <IconButton className='status__action-bar-button' disabled={anonymousAccess} title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} />
  146. <IconButton className='status__action-bar-button' disabled={anonymousAccess || !publicStatus} active={status.get('reblogged')} pressed={status.get('reblogged')} title={!publicStatus ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} />
  147. <IconButton className='status__action-bar-button star-icon' disabled={anonymousAccess} animate active={status.get('favourited')} pressed={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} />
  148. {shareButton}
  149. <div className='status__action-bar-dropdown'>
  150. <DropdownMenuContainer disabled={anonymousAccess} status={status} items={menu} icon='ellipsis-h' size={18} direction='right' ariaLabel='More' />
  151. </div>
  152. </div>
  153. );
  154. }
  155. }