The code powering m.abunchtell.com https://m.abunchtell.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

189 строки
7.1 KiB

  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. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  12. mute: { id: 'account.mute', defaultMessage: 'Mute @{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. report: { id: 'status.report', defaultMessage: 'Report @{name}' },
  23. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  24. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  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. @injectIntl
  30. export default class StatusActionBar extends ImmutablePureComponent {
  31. static contextTypes = {
  32. router: PropTypes.object,
  33. };
  34. static propTypes = {
  35. status: ImmutablePropTypes.map.isRequired,
  36. onReply: PropTypes.func,
  37. onFavourite: PropTypes.func,
  38. onReblog: PropTypes.func,
  39. onDelete: PropTypes.func,
  40. onMention: PropTypes.func,
  41. onMute: PropTypes.func,
  42. onBlock: PropTypes.func,
  43. onReport: PropTypes.func,
  44. onEmbed: PropTypes.func,
  45. onMuteConversation: PropTypes.func,
  46. onPin: PropTypes.func,
  47. withDismiss: PropTypes.bool,
  48. intl: PropTypes.object.isRequired,
  49. };
  50. // Avoid checking props that are functions (and whose equality will always
  51. // evaluate to false. See react-immutable-pure-component for usage.
  52. updateOnProps = [
  53. 'status',
  54. 'withDismiss',
  55. ]
  56. handleReplyClick = () => {
  57. this.props.onReply(this.props.status, this.context.router.history);
  58. }
  59. handleShareClick = () => {
  60. navigator.share({
  61. text: this.props.status.get('search_index'),
  62. url: this.props.status.get('url'),
  63. });
  64. }
  65. handleFavouriteClick = () => {
  66. this.props.onFavourite(this.props.status);
  67. }
  68. handleReblogClick = (e) => {
  69. this.props.onReblog(this.props.status, e);
  70. }
  71. handleDeleteClick = () => {
  72. this.props.onDelete(this.props.status);
  73. }
  74. handlePinClick = () => {
  75. this.props.onPin(this.props.status);
  76. }
  77. handleMentionClick = () => {
  78. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  79. }
  80. handleMuteClick = () => {
  81. this.props.onMute(this.props.status.get('account'));
  82. }
  83. handleBlockClick = () => {
  84. this.props.onBlock(this.props.status.get('account'));
  85. }
  86. handleOpen = () => {
  87. this.context.router.history.push(`/statuses/${this.props.status.get('id')}`);
  88. }
  89. handleEmbed = () => {
  90. this.props.onEmbed(this.props.status);
  91. }
  92. handleReport = () => {
  93. this.props.onReport(this.props.status);
  94. }
  95. handleConversationMuteClick = () => {
  96. this.props.onMuteConversation(this.props.status);
  97. }
  98. render () {
  99. const { status, intl, withDismiss } = this.props;
  100. const mutingConversation = status.get('muted');
  101. const anonymousAccess = !me;
  102. const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
  103. let menu = [];
  104. let reblogIcon = 'retweet';
  105. let replyIcon;
  106. let replyTitle;
  107. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  108. if (publicStatus) {
  109. menu.push({ text: intl.formatMessage(messages.embed), action: this.handleEmbed });
  110. }
  111. menu.push(null);
  112. if (status.getIn(['account', 'id']) === me || withDismiss) {
  113. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  114. menu.push(null);
  115. }
  116. if (status.getIn(['account', 'id']) === me) {
  117. if (publicStatus) {
  118. menu.push({ text: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), action: this.handlePinClick });
  119. }
  120. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  121. } else {
  122. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  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. }
  128. if (status.get('visibility') === 'direct') {
  129. reblogIcon = 'envelope';
  130. } else if (status.get('visibility') === 'private') {
  131. reblogIcon = 'lock';
  132. }
  133. if (status.get('in_reply_to_id', null) === null) {
  134. replyIcon = 'reply';
  135. replyTitle = intl.formatMessage(messages.reply);
  136. } else {
  137. replyIcon = 'reply-all';
  138. replyTitle = intl.formatMessage(messages.replyAll);
  139. }
  140. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  141. <IconButton className='status__action-bar-button' title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShareClick} />
  142. );
  143. return (
  144. <div className='status__action-bar'>
  145. <IconButton className='status__action-bar-button' disabled={anonymousAccess} title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} />
  146. <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} />
  147. <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} />
  148. {shareButton}
  149. <div className='status__action-bar-dropdown'>
  150. <DropdownMenuContainer disabled={anonymousAccess} status={status} items={menu} icon='ellipsis-h' size={18} direction='right' ariaLabel={intl.formatMessage(messages.more)} />
  151. </div>
  152. </div>
  153. );
  154. }
  155. }