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.

172 lines
5.2 KiB

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