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

172 lines
5.0 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. boostModal: state.getIn(['meta', 'boost_modal']),
  41. autoPlayGif: state.getIn(['meta', 'auto_play_gif'])
  42. });
  43. return mapStateToProps;
  44. };
  45. const Status = React.createClass({
  46. contextTypes: {
  47. router: React.PropTypes.object
  48. },
  49. propTypes: {
  50. params: React.PropTypes.object.isRequired,
  51. dispatch: React.PropTypes.func.isRequired,
  52. status: ImmutablePropTypes.map,
  53. ancestorsIds: ImmutablePropTypes.list,
  54. descendantsIds: ImmutablePropTypes.list,
  55. me: React.PropTypes.number,
  56. boostModal: React.PropTypes.bool,
  57. autoPlayGif: React.PropTypes.bool
  58. },
  59. mixins: [PureRenderMixin],
  60. componentWillMount () {
  61. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  62. },
  63. componentWillReceiveProps (nextProps) {
  64. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  65. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  66. }
  67. },
  68. handleFavouriteClick (status) {
  69. if (status.get('favourited')) {
  70. this.props.dispatch(unfavourite(status));
  71. } else {
  72. this.props.dispatch(favourite(status));
  73. }
  74. },
  75. handleReplyClick (status) {
  76. this.props.dispatch(replyCompose(status, this.context.router));
  77. },
  78. handleModalReblog (status) {
  79. this.props.dispatch(reblog(status));
  80. },
  81. handleReblogClick (status, e) {
  82. if (status.get('reblogged')) {
  83. this.props.dispatch(unreblog(status));
  84. } else {
  85. if (e.shiftKey || !this.props.boostModal) {
  86. this.handleModalReblog(status);
  87. } else {
  88. this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
  89. }
  90. }
  91. },
  92. handleDeleteClick (status) {
  93. this.props.dispatch(deleteStatus(status.get('id')));
  94. },
  95. handleMentionClick (account, router) {
  96. this.props.dispatch(mentionCompose(account, router));
  97. },
  98. handleOpenMedia (media, index) {
  99. this.props.dispatch(openModal('MEDIA', { media, index }));
  100. },
  101. handleOpenVideo (media, time) {
  102. this.props.dispatch(openModal('VIDEO', { media, time }));
  103. },
  104. handleReport (status) {
  105. this.props.dispatch(initReport(status.get('account'), status));
  106. },
  107. renderChildren (list) {
  108. return list.map(id => <StatusContainer key={id} id={id} />);
  109. },
  110. render () {
  111. let ancestors, descendants;
  112. const { status, ancestorsIds, descendantsIds, me, autoPlayGif } = this.props;
  113. if (status === null) {
  114. return (
  115. <Column>
  116. <ColumnBackButton />
  117. <MissingIndicator />
  118. </Column>
  119. );
  120. }
  121. const account = status.get('account');
  122. if (ancestorsIds && ancestorsIds.size > 0) {
  123. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  124. }
  125. if (descendantsIds && descendantsIds.size > 0) {
  126. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  127. }
  128. return (
  129. <Column>
  130. <ColumnBackButton />
  131. <ScrollContainer scrollKey='thread'>
  132. <div className='scrollable'>
  133. {ancestors}
  134. <DetailedStatus status={status} autoPlayGif={autoPlayGif} me={me} onOpenVideo={this.handleOpenVideo} onOpenMedia={this.handleOpenMedia} />
  135. <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} onReport={this.handleReport} />
  136. {descendants}
  137. </div>
  138. </ScrollContainer>
  139. </Column>
  140. );
  141. }
  142. });
  143. export default connect(makeMapStateToProps)(Status);