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

126 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 { 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. autoPlayGif: state.getIn(['meta', 'auto_play_gif']),
  38. });
  39. return mapStateToProps;
  40. };
  41. const mapDispatchToProps = (dispatch, { intl }) => ({
  42. onReply (status, router) {
  43. dispatch(replyCompose(status, router));
  44. },
  45. onModalReblog (status) {
  46. dispatch(reblog(status));
  47. },
  48. onReblog (status, e) {
  49. if (status.get('reblogged')) {
  50. dispatch(unreblog(status));
  51. } else {
  52. if (e.shiftKey || !this.boostModal) {
  53. this.onModalReblog(status);
  54. } else {
  55. dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
  56. }
  57. }
  58. },
  59. onFavourite (status) {
  60. if (status.get('favourited')) {
  61. dispatch(unfavourite(status));
  62. } else {
  63. dispatch(favourite(status));
  64. }
  65. },
  66. onDelete (status) {
  67. dispatch(openModal('CONFIRM', {
  68. message: intl.formatMessage(messages.deleteMessage),
  69. confirm: intl.formatMessage(messages.deleteConfirm),
  70. onConfirm: () => dispatch(deleteStatus(status.get('id'))),
  71. }));
  72. },
  73. onMention (account, router) {
  74. dispatch(mentionCompose(account, router));
  75. },
  76. onOpenMedia (media, index) {
  77. dispatch(openModal('MEDIA', { media, index }));
  78. },
  79. onOpenVideo (media, time) {
  80. dispatch(openModal('VIDEO', { media, time }));
  81. },
  82. onBlock (account) {
  83. dispatch(openModal('CONFIRM', {
  84. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  85. confirm: intl.formatMessage(messages.blockConfirm),
  86. onConfirm: () => dispatch(blockAccount(account.get('id'))),
  87. }));
  88. },
  89. onReport (status) {
  90. dispatch(initReport(status.get('account'), status));
  91. },
  92. onMute (account) {
  93. dispatch(openModal('CONFIRM', {
  94. message: <FormattedMessage id='confirmations.mute.message' defaultMessage='Are you sure you want to mute {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  95. confirm: intl.formatMessage(messages.muteConfirm),
  96. onConfirm: () => dispatch(muteAccount(account.get('id'))),
  97. }));
  98. },
  99. onMuteConversation (status) {
  100. if (status.get('muted')) {
  101. dispatch(unmuteStatus(status.get('id')));
  102. } else {
  103. dispatch(muteStatus(status.get('id')));
  104. }
  105. },
  106. });
  107. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));