logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

status_action_bar.js (6523B)


  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. import { me } from '../initial_state';
  9. const messages = defineMessages({
  10. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  11. direct: { id: 'status.direct', defaultMessage: 'Direct message @{name}' },
  12. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  13. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  14. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  15. share: { id: 'status.share', defaultMessage: 'Share' },
  16. more: { id: 'status.more', defaultMessage: 'More' },
  17. replyAll: { id: 'status.replyAll', defaultMessage: 'Reply to thread' },
  18. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  19. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  20. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  21. open: { id: 'status.open', defaultMessage: 'Expand this status' },
  22. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  23. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  24. });
  25. @injectIntl
  26. export default class StatusActionBar extends ImmutablePureComponent {
  27. static contextTypes = {
  28. router: PropTypes.object,
  29. };
  30. static propTypes = {
  31. status: ImmutablePropTypes.map.isRequired,
  32. onReply: PropTypes.func,
  33. onFavourite: PropTypes.func,
  34. onReblog: PropTypes.func,
  35. onDelete: PropTypes.func,
  36. onDirect: PropTypes.func,
  37. onMention: PropTypes.func,
  38. onBlock: PropTypes.func,
  39. onMuteConversation: PropTypes.func,
  40. onPin: PropTypes.func,
  41. withDismiss: PropTypes.bool,
  42. intl: PropTypes.object.isRequired,
  43. };
  44. // Avoid checking props that are functions (and whose equality will always
  45. // evaluate to false. See react-immutable-pure-component for usage.
  46. updateOnProps = [
  47. 'status',
  48. 'withDismiss',
  49. ]
  50. handleReplyClick = () => {
  51. this.props.onReply(this.props.status, this.context.router.history);
  52. }
  53. handleShareClick = () => {
  54. navigator.share({
  55. text: this.props.status.get('search_index'),
  56. url: this.props.status.get('url'),
  57. }).catch((e) => {
  58. if (e.name !== 'AbortError') console.error(e);
  59. });
  60. }
  61. handleFavouriteClick = () => {
  62. this.props.onFavourite(this.props.status);
  63. }
  64. handleReblogClick = (e) => {
  65. this.props.onReblog(this.props.status, e);
  66. }
  67. handleDeleteClick = () => {
  68. this.props.onDelete(this.props.status);
  69. }
  70. handlePinClick = () => {
  71. this.props.onPin(this.props.status);
  72. }
  73. handleMentionClick = () => {
  74. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  75. }
  76. handleDirectClick = () => {
  77. this.props.onDirect(this.props.status.get('account'), this.context.router.history);
  78. }
  79. handleBlockClick = () => {
  80. this.props.onBlock(this.props.status.get('account'));
  81. }
  82. handleOpen = () => {
  83. this.context.router.history.push(`/statuses/${this.props.status.get('id')}`);
  84. }
  85. handleConversationMuteClick = () => {
  86. this.props.onMuteConversation(this.props.status);
  87. }
  88. render () {
  89. const { status, intl, withDismiss } = this.props;
  90. const mutingConversation = status.get('muted');
  91. const anonymousAccess = !me;
  92. const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
  93. let menu = [];
  94. let reblogIcon = 'retweet';
  95. let replyIcon;
  96. let replyTitle;
  97. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  98. menu.push(null);
  99. if (status.getIn(['account', 'id']) === me || withDismiss) {
  100. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  101. menu.push(null);
  102. }
  103. if (status.getIn(['account', 'id']) === me) {
  104. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  105. } else {
  106. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  107. menu.push({ text: intl.formatMessage(messages.direct, { name: status.getIn(['account', 'username']) }), action: this.handleDirectClick });
  108. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  109. }
  110. if (status.get('visibility') === 'direct') {
  111. reblogIcon = 'envelope';
  112. } else if (status.get('visibility') === 'private') {
  113. reblogIcon = 'lock';
  114. }
  115. if (status.get('in_reply_to_id', null) === null) {
  116. replyIcon = 'reply';
  117. replyTitle = intl.formatMessage(messages.reply);
  118. } else {
  119. replyIcon = 'reply-all';
  120. replyTitle = intl.formatMessage(messages.replyAll);
  121. }
  122. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  123. <IconButton className='status__action-bar-button' title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShareClick} />
  124. );
  125. return (
  126. <div className='status__action-bar'>
  127. <IconButton className='status__action-bar-button' disabled={anonymousAccess} title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} />
  128. <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} />
  129. <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} />
  130. {shareButton}
  131. <div className='status__action-bar-dropdown'>
  132. <DropdownMenuContainer disabled={anonymousAccess} status={status} items={menu} icon='ellipsis-h' size={18} direction='right' title={intl.formatMessage(messages.more)} />
  133. </div>
  134. </div>
  135. );
  136. }
  137. }