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.
 
 
 
 

159 lines
4.3 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. 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? You will lose all replies, boosts and favourites to it.' },
  37. blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
  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(replyCompose(status, router));
  49. },
  50. onModalReblog (status) {
  51. dispatch(reblog(status));
  52. },
  53. onReblog (status, e) {
  54. if (status.get('reblogged')) {
  55. dispatch(unreblog(status));
  56. } else {
  57. if (e.shiftKey || !boostModal) {
  58. this.onModalReblog(status);
  59. } else {
  60. dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
  61. }
  62. }
  63. },
  64. onFavourite (status) {
  65. if (status.get('favourited')) {
  66. dispatch(unfavourite(status));
  67. } else {
  68. dispatch(favourite(status));
  69. }
  70. },
  71. onPin (status) {
  72. if (status.get('pinned')) {
  73. dispatch(unpin(status));
  74. } else {
  75. dispatch(pin(status));
  76. }
  77. },
  78. onEmbed (status) {
  79. dispatch(openModal('EMBED', {
  80. url: status.get('url'),
  81. onError: error => dispatch(showAlertForError(error)),
  82. }));
  83. },
  84. onDelete (status, withRedraft = false) {
  85. if (!deleteModal) {
  86. dispatch(deleteStatus(status.get('id'), withRedraft));
  87. } else {
  88. dispatch(openModal('CONFIRM', {
  89. message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
  90. confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
  91. onConfirm: () => dispatch(deleteStatus(status.get('id'), withRedraft)),
  92. }));
  93. }
  94. },
  95. onDirect (account, router) {
  96. dispatch(directCompose(account, router));
  97. },
  98. onMention (account, router) {
  99. dispatch(mentionCompose(account, router));
  100. },
  101. onOpenMedia (media, index) {
  102. dispatch(openModal('MEDIA', { media, index }));
  103. },
  104. onOpenVideo (media, time) {
  105. dispatch(openModal('VIDEO', { media, time }));
  106. },
  107. onBlock (account) {
  108. dispatch(openModal('CONFIRM', {
  109. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  110. confirm: intl.formatMessage(messages.blockConfirm),
  111. onConfirm: () => dispatch(blockAccount(account.get('id'))),
  112. }));
  113. },
  114. onReport (status) {
  115. dispatch(initReport(status.get('account'), status));
  116. },
  117. onMute (account) {
  118. dispatch(initMuteModal(account));
  119. },
  120. onMuteConversation (status) {
  121. if (status.get('muted')) {
  122. dispatch(unmuteStatus(status.get('id')));
  123. } else {
  124. dispatch(muteStatus(status.get('id')));
  125. }
  126. },
  127. onToggleHidden (status) {
  128. if (status.get('hidden')) {
  129. dispatch(revealStatus(status.get('id')));
  130. } else {
  131. dispatch(hideStatus(status.get('id')));
  132. }
  133. },
  134. });
  135. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));