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

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