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

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