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