The code powering m.abunchtell.com https://m.abunchtell.com
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 line
4.6 KiB

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