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.

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