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.
 
 
 
 

145 lines
5.5 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 DropdownMenu from './dropdown_menu';
  6. import { defineMessages, injectIntl } from 'react-intl';
  7. const messages = defineMessages({
  8. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  9. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  10. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  11. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  12. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  13. replyAll: { id: 'status.replyAll', defaultMessage: 'Reply to thread' },
  14. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  15. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  16. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  17. open: { id: 'status.open', defaultMessage: 'Expand this status' },
  18. report: { id: 'status.report', defaultMessage: 'Report @{name}' },
  19. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  20. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  21. });
  22. class StatusActionBar extends React.PureComponent {
  23. static contextTypes = {
  24. router: PropTypes.object
  25. };
  26. static propTypes = {
  27. status: ImmutablePropTypes.map.isRequired,
  28. onReply: PropTypes.func,
  29. onFavourite: PropTypes.func,
  30. onReblog: PropTypes.func,
  31. onDelete: PropTypes.func,
  32. onMention: PropTypes.func,
  33. onMute: PropTypes.func,
  34. onBlock: PropTypes.func,
  35. onReport: PropTypes.func,
  36. onMuteConversation: PropTypes.func,
  37. me: PropTypes.number.isRequired,
  38. withDismiss: PropTypes.bool,
  39. intl: PropTypes.object.isRequired
  40. };
  41. handleReplyClick = () => {
  42. this.props.onReply(this.props.status, this.context.router);
  43. }
  44. handleFavouriteClick = () => {
  45. this.props.onFavourite(this.props.status);
  46. }
  47. handleReblogClick = (e) => {
  48. this.props.onReblog(this.props.status, e);
  49. }
  50. handleDeleteClick = () => {
  51. this.props.onDelete(this.props.status);
  52. }
  53. handleMentionClick = () => {
  54. this.props.onMention(this.props.status.get('account'), this.context.router);
  55. }
  56. handleMuteClick = () => {
  57. this.props.onMute(this.props.status.get('account'));
  58. }
  59. handleBlockClick = () => {
  60. this.props.onBlock(this.props.status.get('account'));
  61. }
  62. handleOpen = () => {
  63. this.context.router.push(`/statuses/${this.props.status.get('id')}`);
  64. }
  65. handleReport = () => {
  66. this.props.onReport(this.props.status);
  67. this.context.router.push('/report');
  68. }
  69. handleConversationMuteClick = () => {
  70. this.props.onMuteConversation(this.props.status);
  71. }
  72. render () {
  73. const { status, me, intl, withDismiss } = this.props;
  74. const reblogDisabled = status.get('visibility') === 'private' || status.get('visibility') === 'direct';
  75. const mutingConversation = status.get('muted');
  76. let menu = [];
  77. let reblogIcon = 'retweet';
  78. let replyIcon;
  79. let replyTitle;
  80. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  81. menu.push(null);
  82. if (withDismiss) {
  83. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  84. menu.push(null);
  85. }
  86. if (status.getIn(['account', 'id']) === me) {
  87. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  88. } else {
  89. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  90. menu.push(null);
  91. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  92. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  93. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  94. }
  95. if (status.get('visibility') === 'direct') {
  96. reblogIcon = 'envelope';
  97. } else if (status.get('visibility') === 'private') {
  98. reblogIcon = 'lock';
  99. }
  100. if (status.get('in_reply_to_id', null) === null) {
  101. replyIcon = "reply";
  102. replyTitle = intl.formatMessage(messages.reply);
  103. } else {
  104. replyIcon = "reply-all";
  105. replyTitle = intl.formatMessage(messages.replyAll);
  106. }
  107. return (
  108. <div className='status__action-bar'>
  109. <div className='status__action-bar-button-wrapper'><IconButton title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} /></div>
  110. <div className='status__action-bar-button-wrapper'><IconButton disabled={reblogDisabled} active={status.get('reblogged')} title={reblogDisabled ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} /></div>
  111. <div className='status__action-bar-button-wrapper'><IconButton animate={true} active={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} className='star-icon' /></div>
  112. <div className='status__action-bar-dropdown'>
  113. <DropdownMenu items={menu} icon='ellipsis-h' size={18} direction="right" ariaLabel="More"/>
  114. </div>
  115. </div>
  116. );
  117. }
  118. }
  119. export default injectIntl(StatusActionBar);