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.

174 lines
7.2 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import IconButton from '../../../components/icon_button';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
  6. import { defineMessages, injectIntl } from 'react-intl';
  7. import { me } from '../../../initial_state';
  8. const messages = defineMessages({
  9. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  10. redraft: { id: 'status.redraft', defaultMessage: 'Delete & re-draft' },
  11. direct: { id: 'status.direct', defaultMessage: 'Direct message @{name}' },
  12. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  13. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  14. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  15. reblog_private: { id: 'status.reblog_private', defaultMessage: 'Boost to original audience' },
  16. cancel_reblog_private: { id: 'status.cancel_reblog_private', defaultMessage: 'Unboost' },
  17. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  18. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  19. mute: { id: 'status.mute', defaultMessage: 'Mute @{name}' },
  20. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  21. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  22. block: { id: 'status.block', defaultMessage: 'Block @{name}' },
  23. report: { id: 'status.report', defaultMessage: 'Report @{name}' },
  24. share: { id: 'status.share', defaultMessage: 'Share' },
  25. pin: { id: 'status.pin', defaultMessage: 'Pin on profile' },
  26. unpin: { id: 'status.unpin', defaultMessage: 'Unpin from profile' },
  27. embed: { id: 'status.embed', defaultMessage: 'Embed' },
  28. });
  29. export default @injectIntl
  30. class ActionBar extends React.PureComponent {
  31. static contextTypes = {
  32. router: PropTypes.object,
  33. };
  34. static propTypes = {
  35. status: ImmutablePropTypes.map.isRequired,
  36. onReply: PropTypes.func.isRequired,
  37. onReblog: PropTypes.func.isRequired,
  38. onFavourite: PropTypes.func.isRequired,
  39. onDelete: PropTypes.func.isRequired,
  40. onDirect: PropTypes.func.isRequired,
  41. onMention: PropTypes.func.isRequired,
  42. onMute: PropTypes.func,
  43. onMuteConversation: PropTypes.func,
  44. onBlock: PropTypes.func,
  45. onReport: PropTypes.func,
  46. onPin: PropTypes.func,
  47. onEmbed: PropTypes.func,
  48. intl: PropTypes.object.isRequired,
  49. };
  50. handleReplyClick = () => {
  51. this.props.onReply(this.props.status);
  52. }
  53. handleReblogClick = (e) => {
  54. this.props.onReblog(this.props.status, e);
  55. }
  56. handleFavouriteClick = () => {
  57. this.props.onFavourite(this.props.status);
  58. }
  59. handleDeleteClick = () => {
  60. this.props.onDelete(this.props.status, this.context.router.history);
  61. }
  62. handleRedraftClick = () => {
  63. this.props.onDelete(this.props.status, this.context.router.history, true);
  64. }
  65. handleDirectClick = () => {
  66. this.props.onDirect(this.props.status.get('account'), this.context.router.history);
  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. handleConversationMuteClick = () => {
  75. this.props.onMuteConversation(this.props.status);
  76. }
  77. handleBlockClick = () => {
  78. this.props.onBlock(this.props.status.get('account'));
  79. }
  80. handleReport = () => {
  81. this.props.onReport(this.props.status);
  82. }
  83. handlePinClick = () => {
  84. this.props.onPin(this.props.status);
  85. }
  86. handleShare = () => {
  87. navigator.share({
  88. text: this.props.status.get('search_index'),
  89. url: this.props.status.get('url'),
  90. });
  91. }
  92. handleEmbed = () => {
  93. this.props.onEmbed(this.props.status);
  94. }
  95. render () {
  96. const { status, intl } = this.props;
  97. const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
  98. const mutingConversation = status.get('muted');
  99. let menu = [];
  100. if (publicStatus) {
  101. menu.push({ text: intl.formatMessage(messages.embed), action: this.handleEmbed });
  102. menu.push(null);
  103. }
  104. if (me === status.getIn(['account', 'id'])) {
  105. if (publicStatus) {
  106. menu.push({ text: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), action: this.handlePinClick });
  107. } else {
  108. if (status.get('visibility') === 'private') {
  109. menu.push({ text: intl.formatMessage(status.get('reblogged') ? messages.cancel_reblog_private : messages.reblog_private), action: this.handleReblogClick });
  110. }
  111. }
  112. menu.push(null);
  113. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  114. menu.push(null);
  115. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  116. menu.push({ text: intl.formatMessage(messages.redraft), action: this.handleRedraftClick });
  117. } else {
  118. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  119. menu.push({ text: intl.formatMessage(messages.direct, { name: status.getIn(['account', 'username']) }), action: this.handleDirectClick });
  120. menu.push(null);
  121. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  122. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  123. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  124. }
  125. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  126. <div className='detailed-status__button'><IconButton title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShare} /></div>
  127. );
  128. let reblogIcon = 'retweet';
  129. if (status.get('visibility') === 'direct') reblogIcon = 'envelope';
  130. else if (status.get('visibility') === 'private') reblogIcon = 'lock';
  131. let reblog_disabled = (status.get('visibility') === 'direct' || status.get('visibility') === 'private');
  132. return (
  133. <div className='detailed-status__action-bar'>
  134. <div className='detailed-status__button'><IconButton title={intl.formatMessage(messages.reply)} icon={status.get('in_reply_to_id', null) === null ? 'reply' : 'reply-all'} onClick={this.handleReplyClick} /></div>
  135. <div className='detailed-status__button'><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>
  136. <div className='detailed-status__button'><IconButton className='star-icon' animate active={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} /></div>
  137. {shareButton}
  138. <div className='detailed-status__action-bar-dropdown'>
  139. <DropdownMenuContainer size={18} icon='ellipsis-h' items={menu} direction='left' title='More' />
  140. </div>
  141. </div>
  142. );
  143. }
  144. }