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.

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