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.
 
 
 
 

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