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

208 lines
6.1 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { fetchStatus } from '../../actions/statuses';
  6. import Immutable from 'immutable';
  7. import EmbeddedStatus from '../../components/status';
  8. import MissingIndicator from '../../components/missing_indicator';
  9. import DetailedStatus from './components/detailed_status';
  10. import ActionBar from './components/action_bar';
  11. import Column from '../ui/components/column';
  12. import {
  13. favourite,
  14. unfavourite,
  15. reblog,
  16. unreblog,
  17. } from '../../actions/interactions';
  18. import {
  19. replyCompose,
  20. mentionCompose,
  21. } from '../../actions/compose';
  22. import { deleteStatus } from '../../actions/statuses';
  23. import { initReport } from '../../actions/reports';
  24. import {
  25. makeGetStatus,
  26. getStatusAncestors,
  27. getStatusDescendants,
  28. } from '../../selectors';
  29. import { ScrollContainer } from 'react-router-scroll';
  30. import ColumnBackButton from '../../components/column_back_button';
  31. import StatusContainer from '../../containers/status_container';
  32. import { openModal } from '../../actions/modal';
  33. import { isMobile } from '../../is_mobile';
  34. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  35. import ImmutablePureComponent from 'react-immutable-pure-component';
  36. const messages = defineMessages({
  37. deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
  38. deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this status?' },
  39. });
  40. const makeMapStateToProps = () => {
  41. const getStatus = makeGetStatus();
  42. const mapStateToProps = (state, props) => ({
  43. status: getStatus(state, Number(props.params.statusId)),
  44. ancestorsIds: state.getIn(['contexts', 'ancestors', Number(props.params.statusId)]),
  45. descendantsIds: state.getIn(['contexts', 'descendants', Number(props.params.statusId)]),
  46. me: state.getIn(['meta', 'me']),
  47. boostModal: state.getIn(['meta', 'boost_modal']),
  48. deleteModal: state.getIn(['meta', 'delete_modal']),
  49. autoPlayGif: state.getIn(['meta', 'auto_play_gif']),
  50. });
  51. return mapStateToProps;
  52. };
  53. class Status extends ImmutablePureComponent {
  54. static contextTypes = {
  55. router: PropTypes.object,
  56. };
  57. static propTypes = {
  58. params: PropTypes.object.isRequired,
  59. dispatch: PropTypes.func.isRequired,
  60. status: ImmutablePropTypes.map,
  61. ancestorsIds: ImmutablePropTypes.list,
  62. descendantsIds: ImmutablePropTypes.list,
  63. me: PropTypes.number,
  64. boostModal: PropTypes.bool,
  65. deleteModal: PropTypes.bool,
  66. autoPlayGif: PropTypes.bool,
  67. intl: PropTypes.object.isRequired,
  68. };
  69. componentWillMount () {
  70. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  71. }
  72. componentWillReceiveProps (nextProps) {
  73. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  74. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  75. }
  76. }
  77. handleFavouriteClick = (status) => {
  78. if (status.get('favourited')) {
  79. this.props.dispatch(unfavourite(status));
  80. } else {
  81. this.props.dispatch(favourite(status));
  82. }
  83. }
  84. handleReplyClick = (status) => {
  85. this.props.dispatch(replyCompose(status, this.context.router.history));
  86. }
  87. handleModalReblog = (status) => {
  88. this.props.dispatch(reblog(status));
  89. }
  90. handleReblogClick = (status, e) => {
  91. if (status.get('reblogged')) {
  92. this.props.dispatch(unreblog(status));
  93. } else {
  94. if (e.shiftKey || !this.props.boostModal) {
  95. this.handleModalReblog(status);
  96. } else {
  97. this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
  98. }
  99. }
  100. }
  101. handleDeleteClick = (status) => {
  102. const { dispatch, intl } = this.props;
  103. if (!this.props.deleteModal) {
  104. dispatch(deleteStatus(status.get('id')));
  105. } else {
  106. dispatch(openModal('CONFIRM', {
  107. message: intl.formatMessage(messages.deleteMessage),
  108. confirm: intl.formatMessage(messages.deleteConfirm),
  109. onConfirm: () => dispatch(deleteStatus(status.get('id'))),
  110. }));
  111. }
  112. }
  113. handleMentionClick = (account, router) => {
  114. this.props.dispatch(mentionCompose(account, router));
  115. }
  116. handleOpenMedia = (media, index) => {
  117. this.props.dispatch(openModal('MEDIA', { media, index }));
  118. }
  119. handleOpenVideo = (media, time) => {
  120. this.props.dispatch(openModal('VIDEO', { media, time }));
  121. }
  122. handleReport = (status) => {
  123. this.props.dispatch(initReport(status.get('account'), status));
  124. }
  125. renderChildren (list) {
  126. return list.map(id => <StatusContainer key={id} id={id} />);
  127. }
  128. render () {
  129. let ancestors, descendants;
  130. const { status, ancestorsIds, descendantsIds, me, autoPlayGif } = this.props;
  131. if (status === null) {
  132. return (
  133. <Column>
  134. <ColumnBackButton />
  135. <MissingIndicator />
  136. </Column>
  137. );
  138. }
  139. const account = status.get('account');
  140. if (ancestorsIds && ancestorsIds.size > 0) {
  141. ancestors = <div>{this.renderChildren(ancestorsIds)}</div>;
  142. }
  143. if (descendantsIds && descendantsIds.size > 0) {
  144. descendants = <div>{this.renderChildren(descendantsIds)}</div>;
  145. }
  146. return (
  147. <Column>
  148. <ColumnBackButton />
  149. <ScrollContainer scrollKey='thread'>
  150. <div className='scrollable detailed-status__wrapper'>
  151. {ancestors}
  152. <DetailedStatus
  153. status={status}
  154. autoPlayGif={autoPlayGif}
  155. me={me}
  156. onOpenVideo={this.handleOpenVideo}
  157. onOpenMedia={this.handleOpenMedia}
  158. />
  159. <ActionBar
  160. status={status}
  161. me={me}
  162. onReply={this.handleReplyClick}
  163. onFavourite={this.handleFavouriteClick}
  164. onReblog={this.handleReblogClick}
  165. onDelete={this.handleDeleteClick}
  166. onMention={this.handleMentionClick}
  167. onReport={this.handleReport}
  168. />
  169. {descendants}
  170. </div>
  171. </ScrollContainer>
  172. </Column>
  173. );
  174. }
  175. }
  176. export default injectIntl(connect(makeMapStateToProps)(Status));