闭社主体 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.

156 lines
4.4 KiB

  1. import { connect } from 'react-redux';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { fetchStatus } from '../../actions/statuses';
  5. import Immutable from 'immutable';
  6. import EmbeddedStatus from '../../components/status';
  7. import MissingIndicator from '../../components/missing_indicator';
  8. import DetailedStatus from './components/detailed_status';
  9. import ActionBar from './components/action_bar';
  10. import Column from '../ui/components/column';
  11. import {
  12. favourite,
  13. unfavourite,
  14. reblog,
  15. unreblog
  16. } from '../../actions/interactions';
  17. import {
  18. replyCompose,
  19. mentionCompose
  20. } from '../../actions/compose';
  21. import { deleteStatus } from '../../actions/statuses';
  22. import { initReport } from '../../actions/reports';
  23. import {
  24. makeGetStatus,
  25. getStatusAncestors,
  26. getStatusDescendants
  27. } from '../../selectors';
  28. import { ScrollContainer } from 'react-router-scroll';
  29. import ColumnBackButton from '../../components/column_back_button';
  30. import StatusContainer from '../../containers/status_container';
  31. import { openModal } from '../../actions/modal';
  32. import { isMobile } from '../../is_mobile'
  33. const makeMapStateToProps = () => {
  34. const getStatus = makeGetStatus();
  35. const mapStateToProps = (state, props) => ({
  36. status: getStatus(state, Number(props.params.statusId)),
  37. ancestorsIds: state.getIn(['timelines', 'ancestors', Number(props.params.statusId)]),
  38. descendantsIds: state.getIn(['timelines', 'descendants', Number(props.params.statusId)]),
  39. me: state.getIn(['meta', 'me'])
  40. });
  41. return mapStateToProps;
  42. };
  43. const Status = React.createClass({
  44. contextTypes: {
  45. router: React.PropTypes.object
  46. },
  47. propTypes: {
  48. params: React.PropTypes.object.isRequired,
  49. dispatch: React.PropTypes.func.isRequired,
  50. status: ImmutablePropTypes.map,
  51. ancestorsIds: ImmutablePropTypes.list,
  52. descendantsIds: ImmutablePropTypes.list,
  53. me: React.PropTypes.number
  54. },
  55. mixins: [PureRenderMixin],
  56. componentWillMount () {
  57. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  58. },
  59. componentWillReceiveProps (nextProps) {
  60. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  61. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  62. }
  63. },
  64. handleFavouriteClick (status) {
  65. if (status.get('favourited')) {
  66. this.props.dispatch(unfavourite(status));
  67. } else {
  68. this.props.dispatch(favourite(status));
  69. }
  70. },
  71. handleReplyClick (status) {
  72. this.props.dispatch(replyCompose(status, this.context.router));
  73. },
  74. handleReblogClick (status) {
  75. if (status.get('reblogged')) {
  76. this.props.dispatch(unreblog(status));
  77. } else {
  78. this.props.dispatch(reblog(status));
  79. }
  80. },
  81. handleDeleteClick (status) {
  82. this.props.dispatch(deleteStatus(status.get('id')));
  83. },
  84. handleMentionClick (account, router) {
  85. this.props.dispatch(mentionCompose(account, router));
  86. },
  87. handleOpenMedia (media, index) {
  88. this.props.dispatch(openModal('MEDIA', { media, index }));
  89. },
  90. handleReport (status) {
  91. this.props.dispatch(initReport(status.get('account'), status));
  92. },
  93. renderChildren (list) {
  94. return list.map(id => <StatusContainer key={id} id={id} />);
  95. },
  96. render () {
  97. let ancestors, descendants;
  98. const { status, ancestorsIds, descendantsIds, me } = this.props;
  99. if (status === null) {
  100. return (
  101. <Column>
  102. <ColumnBackButton />
  103. <MissingIndicator />
  104. </Column>
  105. );
  106. }
  107. const account = status.get('account');
  108. if (ancestorsIds && ancestorsIds.size > 0) {
  109. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  110. }
  111. if (descendantsIds && descendantsIds.size > 0) {
  112. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  113. }
  114. return (
  115. <Column>
  116. <ColumnBackButton />
  117. <ScrollContainer scrollKey='thread'>
  118. <div className='scrollable'>
  119. {ancestors}
  120. <DetailedStatus status={status} me={me} onOpenMedia={this.handleOpenMedia} />
  121. <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} onReport={this.handleReport} />
  122. {descendants}
  123. </div>
  124. </ScrollContainer>
  125. </Column>
  126. );
  127. }
  128. });
  129. export default connect(makeMapStateToProps)(Status);