The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

191 lines
7.2 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. }).catch((e) => {
  64. if (e.name !== 'AbortError') console.error(e);
  65. });
  66. }
  67. handleFavouriteClick = () => {
  68. this.props.onFavourite(this.props.status);
  69. }
  70. handleReblogClick = (e) => {
  71. this.props.onReblog(this.props.status, e);
  72. }
  73. handleDeleteClick = () => {
  74. this.props.onDelete(this.props.status);
  75. }
  76. handlePinClick = () => {
  77. this.props.onPin(this.props.status);
  78. }
  79. handleMentionClick = () => {
  80. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  81. }
  82. handleMuteClick = () => {
  83. this.props.onMute(this.props.status.get('account'));
  84. }
  85. handleBlockClick = () => {
  86. this.props.onBlock(this.props.status.get('account'));
  87. }
  88. handleOpen = () => {
  89. this.context.router.history.push(`/statuses/${this.props.status.get('id')}`);
  90. }
  91. handleEmbed = () => {
  92. this.props.onEmbed(this.props.status);
  93. }
  94. handleReport = () => {
  95. this.props.onReport(this.props.status);
  96. }
  97. handleConversationMuteClick = () => {
  98. this.props.onMuteConversation(this.props.status);
  99. }
  100. render () {
  101. const { status, intl, withDismiss } = this.props;
  102. const mutingConversation = status.get('muted');
  103. const anonymousAccess = !me;
  104. const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
  105. let menu = [];
  106. let reblogIcon = 'retweet';
  107. let replyIcon;
  108. let replyTitle;
  109. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  110. if (publicStatus) {
  111. menu.push({ text: intl.formatMessage(messages.embed), action: this.handleEmbed });
  112. }
  113. menu.push(null);
  114. if (status.getIn(['account', 'id']) === me || withDismiss) {
  115. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  116. menu.push(null);
  117. }
  118. if (status.getIn(['account', 'id']) === me) {
  119. if (publicStatus) {
  120. menu.push({ text: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), action: this.handlePinClick });
  121. }
  122. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  123. } else {
  124. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  125. menu.push(null);
  126. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  127. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  128. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  129. }
  130. if (status.get('visibility') === 'direct') {
  131. reblogIcon = 'envelope';
  132. } else if (status.get('visibility') === 'private') {
  133. reblogIcon = 'lock';
  134. }
  135. if (status.get('in_reply_to_id', null) === null) {
  136. replyIcon = 'reply';
  137. replyTitle = intl.formatMessage(messages.reply);
  138. } else {
  139. replyIcon = 'reply-all';
  140. replyTitle = intl.formatMessage(messages.replyAll);
  141. }
  142. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  143. <IconButton className='status__action-bar-button' title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShareClick} />
  144. );
  145. return (
  146. <div className='status__action-bar'>
  147. <IconButton className='status__action-bar-button' disabled={anonymousAccess} title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} />
  148. <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} />
  149. <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} />
  150. {shareButton}
  151. <div className='status__action-bar-dropdown'>
  152. <DropdownMenuContainer disabled={anonymousAccess} status={status} items={menu} icon='ellipsis-h' size={18} direction='right' title={intl.formatMessage(messages.more)} />
  153. </div>
  154. </div>
  155. );
  156. }
  157. }