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

197 lines
6.1 KiB

  1. import { connect } from 'react-redux';
  2. import PropTypes from 'prop-types';
  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. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  34. const messages = defineMessages({
  35. deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
  36. deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' }
  37. });
  38. const makeMapStateToProps = () => {
  39. const getStatus = makeGetStatus();
  40. const mapStateToProps = (state, props) => ({
  41. status: getStatus(state, Number(props.params.statusId)),
  42. ancestorsIds: state.getIn(['timelines', 'ancestors', Number(props.params.statusId)]),
  43. descendantsIds: state.getIn(['timelines', 'descendants', Number(props.params.statusId)]),
  44. me: state.getIn(['meta', 'me']),
  45. boostModal: state.getIn(['meta', 'boost_modal']),
  46. autoPlayGif: state.getIn(['meta', 'auto_play_gif'])
  47. });
  48. return mapStateToProps;
  49. };
  50. class Status extends React.PureComponent {
  51. constructor (props, context) {
  52. super(props, context);
  53. this.handleFavouriteClick = this.handleFavouriteClick.bind(this);
  54. this.handleReplyClick = this.handleReplyClick.bind(this);
  55. this.handleModalReblog = this.handleModalReblog.bind(this);
  56. this.handleReblogClick = this.handleReblogClick.bind(this);
  57. this.handleDeleteClick = this.handleDeleteClick.bind(this);
  58. this.handleMentionClick = this.handleMentionClick.bind(this);
  59. this.handleOpenMedia = this.handleOpenMedia.bind(this);
  60. this.handleOpenVideo = this.handleOpenVideo.bind(this);
  61. this.handleReport = this.handleReport.bind(this);
  62. }
  63. componentWillMount () {
  64. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  65. }
  66. componentWillReceiveProps (nextProps) {
  67. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  68. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  69. }
  70. }
  71. handleFavouriteClick (status) {
  72. if (status.get('favourited')) {
  73. this.props.dispatch(unfavourite(status));
  74. } else {
  75. this.props.dispatch(favourite(status));
  76. }
  77. }
  78. handleReplyClick (status) {
  79. this.props.dispatch(replyCompose(status, this.context.router));
  80. }
  81. handleModalReblog (status) {
  82. this.props.dispatch(reblog(status));
  83. }
  84. handleReblogClick (status, e) {
  85. if (status.get('reblogged')) {
  86. this.props.dispatch(unreblog(status));
  87. } else {
  88. if (e.shiftKey || !this.props.boostModal) {
  89. this.handleModalReblog(status);
  90. } else {
  91. this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
  92. }
  93. }
  94. }
  95. handleDeleteClick (status) {
  96. const { dispatch, intl } = this.props;
  97. dispatch(openModal('CONFIRM', {
  98. message: intl.formatMessage(messages.deleteMessage),
  99. confirm: intl.formatMessage(messages.deleteConfirm),
  100. onConfirm: () => dispatch(deleteStatus(status.get('id')))
  101. }));
  102. }
  103. handleMentionClick (account, router) {
  104. this.props.dispatch(mentionCompose(account, router));
  105. }
  106. handleOpenMedia (media, index) {
  107. this.props.dispatch(openModal('MEDIA', { media, index }));
  108. }
  109. handleOpenVideo (media, time) {
  110. this.props.dispatch(openModal('VIDEO', { media, time }));
  111. }
  112. handleReport (status) {
  113. this.props.dispatch(initReport(status.get('account'), status));
  114. }
  115. renderChildren (list) {
  116. return list.map(id => <StatusContainer key={id} id={id} />);
  117. }
  118. render () {
  119. let ancestors, descendants;
  120. const { status, ancestorsIds, descendantsIds, me, autoPlayGif } = this.props;
  121. if (status === null) {
  122. return (
  123. <Column>
  124. <ColumnBackButton />
  125. <MissingIndicator />
  126. </Column>
  127. );
  128. }
  129. const account = status.get('account');
  130. if (ancestorsIds && ancestorsIds.size > 0) {
  131. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  132. }
  133. if (descendantsIds && descendantsIds.size > 0) {
  134. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  135. }
  136. return (
  137. <Column>
  138. <ColumnBackButton />
  139. <ScrollContainer scrollKey='thread'>
  140. <div className='scrollable detailed-status__wrapper'>
  141. {ancestors}
  142. <DetailedStatus status={status} autoPlayGif={autoPlayGif} me={me} onOpenVideo={this.handleOpenVideo} onOpenMedia={this.handleOpenMedia} />
  143. <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} onReport={this.handleReport} />
  144. {descendants}
  145. </div>
  146. </ScrollContainer>
  147. </Column>
  148. );
  149. }
  150. }
  151. Status.contextTypes = {
  152. router: PropTypes.object
  153. };
  154. Status.propTypes = {
  155. params: PropTypes.object.isRequired,
  156. dispatch: PropTypes.func.isRequired,
  157. status: ImmutablePropTypes.map,
  158. ancestorsIds: ImmutablePropTypes.list,
  159. descendantsIds: ImmutablePropTypes.list,
  160. me: PropTypes.number,
  161. boostModal: PropTypes.bool,
  162. autoPlayGif: PropTypes.bool,
  163. intl: PropTypes.object.isRequired
  164. };
  165. export default injectIntl(connect(makeMapStateToProps)(Status));