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.

170 lines
5.0 KiB

  1. import { connect } from 'react-redux';
  2. import DetailedStatus from '../components/detailed_status';
  3. import { makeGetStatus, makeGetPictureInPicture } from '../../../selectors';
  4. import {
  5. replyCompose,
  6. mentionCompose,
  7. directCompose,
  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. muteStatus,
  19. unmuteStatus,
  20. deleteStatus,
  21. hideStatus,
  22. revealStatus,
  23. } from '../../../actions/statuses';
  24. import { initMuteModal } from '../../../actions/mutes';
  25. import { initBlockModal } from '../../../actions/blocks';
  26. import { initBoostModal } from '../../../actions/boosts';
  27. import { initReport } from '../../../actions/reports';
  28. import { openModal } from '../../../actions/modal';
  29. import { defineMessages, injectIntl } from 'react-intl';
  30. import { boostModal, deleteModal } from '../../../initial_state';
  31. import { showAlertForError } from '../../../actions/alerts';
  32. const messages = defineMessages({
  33. deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
  34. deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
  35. redraftConfirm: { id: 'confirmations.redraft.confirm', defaultMessage: 'Delete & redraft' },
  36. redraftMessage: { id: 'confirmations.redraft.message', defaultMessage: 'Are you sure you want to delete this status and re-draft it? Favourites and boosts will be lost, and replies to the original post will be orphaned.' },
  37. replyConfirm: { id: 'confirmations.reply.confirm', defaultMessage: 'Reply' },
  38. replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' },
  39. });
  40. const makeMapStateToProps = () => {
  41. const getStatus = makeGetStatus();
  42. const getPictureInPicture = makeGetPictureInPicture();
  43. const mapStateToProps = (state, props) => ({
  44. status: getStatus(state, props),
  45. domain: state.getIn(['meta', 'domain']),
  46. pictureInPicture: getPictureInPicture(state, props),
  47. });
  48. return mapStateToProps;
  49. };
  50. const mapDispatchToProps = (dispatch, { intl }) => ({
  51. onReply (status, router) {
  52. dispatch((_, getState) => {
  53. let state = getState();
  54. if (state.getIn(['compose', 'text']).trim().length !== 0) {
  55. dispatch(openModal('CONFIRM', {
  56. message: intl.formatMessage(messages.replyMessage),
  57. confirm: intl.formatMessage(messages.replyConfirm),
  58. onConfirm: () => dispatch(replyCompose(status, router)),
  59. }));
  60. } else {
  61. dispatch(replyCompose(status, router));
  62. }
  63. });
  64. },
  65. onModalReblog (status, privacy) {
  66. dispatch(reblog(status, privacy));
  67. },
  68. onReblog (status, e) {
  69. if (status.get('reblogged')) {
  70. dispatch(unreblog(status));
  71. } else {
  72. if (e.shiftKey || !boostModal) {
  73. this.onModalReblog(status);
  74. } else {
  75. dispatch(initBoostModal({ status, onReblog: this.onModalReblog }));
  76. }
  77. }
  78. },
  79. onFavourite (status) {
  80. if (status.get('favourited')) {
  81. dispatch(unfavourite(status));
  82. } else {
  83. dispatch(favourite(status));
  84. }
  85. },
  86. onPin (status) {
  87. if (status.get('pinned')) {
  88. dispatch(unpin(status));
  89. } else {
  90. dispatch(pin(status));
  91. }
  92. },
  93. onEmbed (status) {
  94. dispatch(openModal('EMBED', {
  95. url: status.get('url'),
  96. onError: error => dispatch(showAlertForError(error)),
  97. }));
  98. },
  99. onDelete (status, history, withRedraft = false) {
  100. if (!deleteModal) {
  101. dispatch(deleteStatus(status.get('id'), history, withRedraft));
  102. } else {
  103. dispatch(openModal('CONFIRM', {
  104. message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
  105. confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
  106. onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
  107. }));
  108. }
  109. },
  110. onDirect (account, router) {
  111. dispatch(directCompose(account, router));
  112. },
  113. onMention (account, router) {
  114. dispatch(mentionCompose(account, router));
  115. },
  116. onOpenMedia (media, index) {
  117. dispatch(openModal('MEDIA', { media, index }));
  118. },
  119. onOpenVideo (media, options) {
  120. dispatch(openModal('VIDEO', { media, options }));
  121. },
  122. onBlock (status) {
  123. const account = status.get('account');
  124. dispatch(initBlockModal(account));
  125. },
  126. onReport (status) {
  127. dispatch(initReport(status.get('account'), status));
  128. },
  129. onMute (account) {
  130. dispatch(initMuteModal(account));
  131. },
  132. onMuteConversation (status) {
  133. if (status.get('muted')) {
  134. dispatch(unmuteStatus(status.get('id')));
  135. } else {
  136. dispatch(muteStatus(status.get('id')));
  137. }
  138. },
  139. onToggleHidden (status) {
  140. if (status.get('hidden')) {
  141. dispatch(revealStatus(status.get('id')));
  142. } else {
  143. dispatch(hideStatus(status.get('id')));
  144. }
  145. },
  146. });
  147. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(DetailedStatus));