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

131 lines
3.8 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 { createSelector } from 'reselect';
  23. import { isMobile } from '../is_mobile';
  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. onDelete (status) {
  68. if (!this.deleteModal) {
  69. dispatch(deleteStatus(status.get('id')));
  70. } else {
  71. dispatch(openModal('CONFIRM', {
  72. message: intl.formatMessage(messages.deleteMessage),
  73. confirm: intl.formatMessage(messages.deleteConfirm),
  74. onConfirm: () => dispatch(deleteStatus(status.get('id'))),
  75. }));
  76. }
  77. },
  78. onMention (account, router) {
  79. dispatch(mentionCompose(account, router));
  80. },
  81. onOpenMedia (media, index) {
  82. dispatch(openModal('MEDIA', { media, index }));
  83. },
  84. onOpenVideo (media, time) {
  85. dispatch(openModal('VIDEO', { media, time }));
  86. },
  87. onBlock (account) {
  88. dispatch(openModal('CONFIRM', {
  89. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  90. confirm: intl.formatMessage(messages.blockConfirm),
  91. onConfirm: () => dispatch(blockAccount(account.get('id'))),
  92. }));
  93. },
  94. onReport (status) {
  95. dispatch(initReport(status.get('account'), status));
  96. },
  97. onMute (account) {
  98. dispatch(openModal('CONFIRM', {
  99. message: <FormattedMessage id='confirmations.mute.message' defaultMessage='Are you sure you want to mute {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  100. confirm: intl.formatMessage(messages.muteConfirm),
  101. onConfirm: () => dispatch(muteAccount(account.get('id'))),
  102. }));
  103. },
  104. onMuteConversation (status) {
  105. if (status.get('muted')) {
  106. dispatch(unmuteStatus(status.get('id')));
  107. } else {
  108. dispatch(muteStatus(status.get('id')));
  109. }
  110. },
  111. });
  112. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));