闭社主体 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.

129 lines
3.7 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import Status from '../components/status';
  4. import { makeGetStatus } from '../selectors';
  5. import {
  6. replyCompose,
  7. mentionCompose,
  8. } from '../actions/compose';
  9. import {
  10. reblog,
  11. favourite,
  12. unreblog,
  13. unfavourite,
  14. } from '../actions/interactions';
  15. import {
  16. blockAccount,
  17. muteAccount,
  18. } from '../actions/accounts';
  19. import { muteStatus, unmuteStatus, deleteStatus } from '../actions/statuses';
  20. import { initReport } from '../actions/reports';
  21. import { openModal } from '../actions/modal';
  22. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  23. const messages = defineMessages({
  24. deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
  25. deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
  26. blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
  27. muteConfirm: { id: 'confirmations.mute.confirm', defaultMessage: 'Mute' },
  28. });
  29. const makeMapStateToProps = () => {
  30. const getStatus = makeGetStatus();
  31. const mapStateToProps = (state, props) => ({
  32. status: getStatus(state, props.id),
  33. me: state.getIn(['meta', 'me']),
  34. boostModal: state.getIn(['meta', 'boost_modal']),
  35. deleteModal: state.getIn(['meta', 'delete_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. if (!this.deleteModal) {
  67. dispatch(deleteStatus(status.get('id')));
  68. } else {
  69. dispatch(openModal('CONFIRM', {
  70. message: intl.formatMessage(messages.deleteMessage),
  71. confirm: intl.formatMessage(messages.deleteConfirm),
  72. onConfirm: () => dispatch(deleteStatus(status.get('id'))),
  73. }));
  74. }
  75. },
  76. onMention (account, router) {
  77. dispatch(mentionCompose(account, router));
  78. },
  79. onOpenMedia (media, index) {
  80. dispatch(openModal('MEDIA', { media, index }));
  81. },
  82. onOpenVideo (media, time) {
  83. dispatch(openModal('VIDEO', { media, time }));
  84. },
  85. onBlock (account) {
  86. dispatch(openModal('CONFIRM', {
  87. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  88. confirm: intl.formatMessage(messages.blockConfirm),
  89. onConfirm: () => dispatch(blockAccount(account.get('id'))),
  90. }));
  91. },
  92. onReport (status) {
  93. dispatch(initReport(status.get('account'), status));
  94. },
  95. onMute (account) {
  96. dispatch(openModal('CONFIRM', {
  97. message: <FormattedMessage id='confirmations.mute.message' defaultMessage='Are you sure you want to mute {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  98. confirm: intl.formatMessage(messages.muteConfirm),
  99. onConfirm: () => dispatch(muteAccount(account.get('id'))),
  100. }));
  101. },
  102. onMuteConversation (status) {
  103. if (status.get('muted')) {
  104. dispatch(unmuteStatus(status.get('id')));
  105. } else {
  106. dispatch(muteStatus(status.get('id')));
  107. }
  108. },
  109. });
  110. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));