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

147 lines
4.1 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. pin,
  15. unpin,
  16. } from '../actions/interactions';
  17. import {
  18. blockAccount,
  19. muteAccount,
  20. } from '../actions/accounts';
  21. import { muteStatus, unmuteStatus, deleteStatus, setStatusHeight } from '../actions/statuses';
  22. import { initReport } from '../actions/reports';
  23. import { openModal } from '../actions/modal';
  24. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  25. const messages = defineMessages({
  26. deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
  27. deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
  28. blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
  29. muteConfirm: { id: 'confirmations.mute.confirm', defaultMessage: 'Mute' },
  30. });
  31. const makeMapStateToProps = () => {
  32. const getStatus = makeGetStatus();
  33. const mapStateToProps = (state, props) => ({
  34. status: getStatus(state, props.id),
  35. me: state.getIn(['meta', 'me']),
  36. boostModal: state.getIn(['meta', 'boost_modal']),
  37. deleteModal: state.getIn(['meta', 'delete_modal']),
  38. autoPlayGif: state.getIn(['meta', 'auto_play_gif']),
  39. });
  40. return mapStateToProps;
  41. };
  42. const mapDispatchToProps = (dispatch, { intl }) => ({
  43. onReply (status, router) {
  44. dispatch(replyCompose(status, router));
  45. },
  46. onModalReblog (status) {
  47. dispatch(reblog(status));
  48. },
  49. onReblog (status, e) {
  50. if (status.get('reblogged')) {
  51. dispatch(unreblog(status));
  52. } else {
  53. if (e.shiftKey || !this.boostModal) {
  54. this.onModalReblog(status);
  55. } else {
  56. dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
  57. }
  58. }
  59. },
  60. onFavourite (status) {
  61. if (status.get('favourited')) {
  62. dispatch(unfavourite(status));
  63. } else {
  64. dispatch(favourite(status));
  65. }
  66. },
  67. onPin (status) {
  68. if (status.get('pinned')) {
  69. dispatch(unpin(status));
  70. } else {
  71. dispatch(pin(status));
  72. }
  73. },
  74. onEmbed (status) {
  75. dispatch(openModal('EMBED', { url: status.get('url') }));
  76. },
  77. onDelete (status) {
  78. if (!this.deleteModal) {
  79. dispatch(deleteStatus(status.get('id')));
  80. } else {
  81. dispatch(openModal('CONFIRM', {
  82. message: intl.formatMessage(messages.deleteMessage),
  83. confirm: intl.formatMessage(messages.deleteConfirm),
  84. onConfirm: () => dispatch(deleteStatus(status.get('id'))),
  85. }));
  86. }
  87. },
  88. onMention (account, router) {
  89. dispatch(mentionCompose(account, router));
  90. },
  91. onOpenMedia (media, index) {
  92. dispatch(openModal('MEDIA', { media, index }));
  93. },
  94. onOpenVideo (media, time) {
  95. dispatch(openModal('VIDEO', { media, time }));
  96. },
  97. onBlock (account) {
  98. dispatch(openModal('CONFIRM', {
  99. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  100. confirm: intl.formatMessage(messages.blockConfirm),
  101. onConfirm: () => dispatch(blockAccount(account.get('id'))),
  102. }));
  103. },
  104. onReport (status) {
  105. dispatch(initReport(status.get('account'), status));
  106. },
  107. onMute (account) {
  108. dispatch(openModal('CONFIRM', {
  109. message: <FormattedMessage id='confirmations.mute.message' defaultMessage='Are you sure you want to mute {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  110. confirm: intl.formatMessage(messages.muteConfirm),
  111. onConfirm: () => dispatch(muteAccount(account.get('id'))),
  112. }));
  113. },
  114. onMuteConversation (status) {
  115. if (status.get('muted')) {
  116. dispatch(unmuteStatus(status.get('id')));
  117. } else {
  118. dispatch(muteStatus(status.get('id')));
  119. }
  120. },
  121. onHeightChange (status, height) {
  122. dispatch(setStatusHeight(status.get('id'), height));
  123. },
  124. });
  125. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));