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.

168 lines
4.7 KiB

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