闭社主体 forked from https://github.com/tootsuite/mastodon
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.

107 lines
2.5 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. } from '../actions/compose';
  8. import {
  9. reblog,
  10. favourite,
  11. unreblog,
  12. unfavourite
  13. } from '../actions/interactions';
  14. import { blockAccount } from '../actions/accounts';
  15. import { deleteStatus } from '../actions/statuses';
  16. import { openMedia } from '../actions/modal';
  17. import { createSelector } from 'reselect'
  18. const mapStateToProps = (state, props) => ({
  19. statusBase: state.getIn(['statuses', props.id]),
  20. me: state.getIn(['meta', 'me'])
  21. });
  22. const makeMapStateToPropsInner = () => {
  23. const getStatus = (() => {
  24. return createSelector(
  25. [
  26. (_, base) => base,
  27. (state, base) => (base ? state.getIn(['accounts', base.get('account')]) : null),
  28. (state, base) => (base ? state.getIn(['statuses', base.get('reblog')], null) : null)
  29. ],
  30. (base, account, reblog) => (base ? base.set('account', account).set('reblog', reblog) : null)
  31. );
  32. })();
  33. const mapStateToProps = (state, { statusBase }) => ({
  34. status: getStatus(state, statusBase)
  35. });
  36. return mapStateToProps;
  37. };
  38. const makeMapStateToPropsLast = () => {
  39. const getStatus = (() => {
  40. return createSelector(
  41. [
  42. (_, status) => status,
  43. (state, status) => (status ? state.getIn(['accounts', status.getIn(['reblog', 'account'])], null) : null)
  44. ],
  45. (status, reblogAccount) => (status && status.get('reblog') ? status.setIn(['reblog', 'account'], reblogAccount) : status)
  46. );
  47. })();
  48. const mapStateToProps = (state, { status }) => ({
  49. status: getStatus(state, status)
  50. });
  51. return mapStateToProps;
  52. };
  53. const mapDispatchToProps = (dispatch) => ({
  54. onReply (status, router) {
  55. dispatch(replyCompose(status, router));
  56. },
  57. onReblog (status) {
  58. if (status.get('reblogged')) {
  59. dispatch(unreblog(status));
  60. } else {
  61. dispatch(reblog(status));
  62. }
  63. },
  64. onFavourite (status) {
  65. if (status.get('favourited')) {
  66. dispatch(unfavourite(status));
  67. } else {
  68. dispatch(favourite(status));
  69. }
  70. },
  71. onDelete (status) {
  72. dispatch(deleteStatus(status.get('id')));
  73. },
  74. onMention (account) {
  75. dispatch(mentionCompose(account));
  76. },
  77. onOpenMedia (url) {
  78. dispatch(openMedia(url));
  79. },
  80. onBlock (account) {
  81. dispatch(blockAccount(account.get('id')));
  82. }
  83. });
  84. export default connect(mapStateToProps, mapDispatchToProps)(
  85. connect(makeMapStateToPropsInner)(
  86. connect(makeMapStateToPropsLast)(Status)
  87. )
  88. );