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.

186 lines
5.7 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(['timelines', 'ancestors', Number(props.params.statusId)]),
  45. descendantsIds: state.getIn(['timelines', 'descendants', Number(props.params.statusId)]),
  46. me: state.getIn(['meta', 'me']),
  47. boostModal: state.getIn(['meta', 'boost_modal']),
  48. autoPlayGif: state.getIn(['meta', 'auto_play_gif'])
  49. });
  50. return mapStateToProps;
  51. };
  52. class Status extends ImmutablePureComponent {
  53. static contextTypes = {
  54. router: PropTypes.object
  55. };
  56. static propTypes = {
  57. params: PropTypes.object.isRequired,
  58. dispatch: PropTypes.func.isRequired,
  59. status: ImmutablePropTypes.map,
  60. ancestorsIds: ImmutablePropTypes.list,
  61. descendantsIds: ImmutablePropTypes.list,
  62. me: PropTypes.number,
  63. boostModal: PropTypes.bool,
  64. autoPlayGif: PropTypes.bool,
  65. intl: PropTypes.object.isRequired
  66. };
  67. componentWillMount () {
  68. this.props.dispatch(fetchStatus(Number(this.props.params.statusId)));
  69. }
  70. componentWillReceiveProps (nextProps) {
  71. if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
  72. this.props.dispatch(fetchStatus(Number(nextProps.params.statusId)));
  73. }
  74. }
  75. handleFavouriteClick = (status) => {
  76. if (status.get('favourited')) {
  77. this.props.dispatch(unfavourite(status));
  78. } else {
  79. this.props.dispatch(favourite(status));
  80. }
  81. }
  82. handleReplyClick = (status) => {
  83. this.props.dispatch(replyCompose(status, this.context.router));
  84. }
  85. handleModalReblog = (status) => {
  86. this.props.dispatch(reblog(status));
  87. }
  88. handleReblogClick = (status, e) => {
  89. if (status.get('reblogged')) {
  90. this.props.dispatch(unreblog(status));
  91. } else {
  92. if (e.shiftKey || !this.props.boostModal) {
  93. this.handleModalReblog(status);
  94. } else {
  95. this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
  96. }
  97. }
  98. }
  99. handleDeleteClick = (status) => {
  100. const { dispatch, intl } = this.props;
  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. handleMentionClick = (account, router) => {
  108. this.props.dispatch(mentionCompose(account, router));
  109. }
  110. handleOpenMedia = (media, index) => {
  111. this.props.dispatch(openModal('MEDIA', { media, index }));
  112. }
  113. handleOpenVideo = (media, time) => {
  114. this.props.dispatch(openModal('VIDEO', { media, time }));
  115. }
  116. handleReport = (status) => {
  117. this.props.dispatch(initReport(status.get('account'), status));
  118. }
  119. renderChildren (list) {
  120. return list.map(id => <StatusContainer key={id} id={id} />);
  121. }
  122. render () {
  123. let ancestors, descendants;
  124. const { status, ancestorsIds, descendantsIds, me, autoPlayGif } = this.props;
  125. if (status === null) {
  126. return (
  127. <Column>
  128. <ColumnBackButton />
  129. <MissingIndicator />
  130. </Column>
  131. );
  132. }
  133. const account = status.get('account');
  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 status={status} autoPlayGif={autoPlayGif} me={me} onOpenVideo={this.handleOpenVideo} onOpenMedia={this.handleOpenMedia} />
  147. <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} onReport={this.handleReport} />
  148. {descendants}
  149. </div>
  150. </ScrollContainer>
  151. </Column>
  152. );
  153. }
  154. }
  155. export default injectIntl(connect(makeMapStateToProps)(Status));