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.

195 lines
8.4 KiB

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