闭社主体 forked from https://github.com/tootsuite/mastodon
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.

117 lines
3.4 KiB

  1. import { connect } from 'react-redux';
  2. import Status from '../components/status';
  3. import { makeGetStatus } from '../selectors';
  4. import {
  5. replyCompose,
  6. mentionCompose
  7. } from '../actions/compose';
  8. import {
  9. reblog,
  10. favourite,
  11. unreblog,
  12. unfavourite
  13. } from '../actions/interactions';
  14. import {
  15. blockAccount,
  16. muteAccount
  17. } from '../actions/accounts';
  18. import { deleteStatus } from '../actions/statuses';
  19. import { initReport } from '../actions/reports';
  20. import { openModal } from '../actions/modal';
  21. import { createSelector } from 'reselect'
  22. import { isMobile } from '../is_mobile'
  23. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  24. const messages = defineMessages({
  25. deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
  26. deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
  27. blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
  28. muteConfirm: { id: 'confirmations.mute.confirm', defaultMessage: 'Mute' },
  29. });
  30. const makeMapStateToProps = () => {
  31. const getStatus = makeGetStatus();
  32. const mapStateToProps = (state, props) => ({
  33. status: getStatus(state, props.id),
  34. me: state.getIn(['meta', 'me']),
  35. boostModal: state.getIn(['meta', 'boost_modal']),
  36. autoPlayGif: state.getIn(['meta', 'auto_play_gif'])
  37. });
  38. return mapStateToProps;
  39. };
  40. const mapDispatchToProps = (dispatch, { intl }) => ({
  41. onReply (status, router) {
  42. dispatch(replyCompose(status, router));
  43. },
  44. onModalReblog (status) {
  45. dispatch(reblog(status));
  46. },
  47. onReblog (status, e) {
  48. if (status.get('reblogged')) {
  49. dispatch(unreblog(status));
  50. } else {
  51. if (e.shiftKey || !this.boostModal) {
  52. this.onModalReblog(status);
  53. } else {
  54. dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
  55. }
  56. }
  57. },
  58. onFavourite (status) {
  59. if (status.get('favourited')) {
  60. dispatch(unfavourite(status));
  61. } else {
  62. dispatch(favourite(status));
  63. }
  64. },
  65. onDelete (status) {
  66. dispatch(openModal('CONFIRM', {
  67. message: intl.formatMessage(messages.deleteMessage),
  68. confirm: intl.formatMessage(messages.deleteConfirm),
  69. onConfirm: () => dispatch(deleteStatus(status.get('id')))
  70. }));
  71. },
  72. onMention (account, router) {
  73. dispatch(mentionCompose(account, router));
  74. },
  75. onOpenMedia (media, index) {
  76. dispatch(openModal('MEDIA', { media, index }));
  77. },
  78. onOpenVideo (media, time) {
  79. dispatch(openModal('VIDEO', { media, time }));
  80. },
  81. onBlock (account) {
  82. dispatch(openModal('CONFIRM', {
  83. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  84. confirm: intl.formatMessage(messages.blockConfirm),
  85. onConfirm: () => dispatch(blockAccount(account.get('id')))
  86. }));
  87. },
  88. onReport (status) {
  89. dispatch(initReport(status.get('account'), status));
  90. },
  91. onMute (account) {
  92. dispatch(openModal('CONFIRM', {
  93. message: <FormattedMessage id='confirmations.mute.message' defaultMessage='Are you sure you want to mute {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  94. confirm: intl.formatMessage(messages.muteConfirm),
  95. onConfirm: () => dispatch(muteAccount(account.get('id')))
  96. }));
  97. },
  98. });
  99. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));