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.

127 lines
4.6 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import Avatar from '../../../components/avatar';
  5. import DisplayName from '../../../components/display_name';
  6. import StatusContent from '../../../components/status_content';
  7. import MediaGallery from '../../../components/media_gallery';
  8. import AttachmentList from '../../../components/attachment_list';
  9. import { Link } from 'react-router-dom';
  10. import { FormattedDate, FormattedNumber } from 'react-intl';
  11. import CardContainer from '../containers/card_container';
  12. import ImmutablePureComponent from 'react-immutable-pure-component';
  13. import Video from '../../video';
  14. export default class DetailedStatus extends ImmutablePureComponent {
  15. static contextTypes = {
  16. router: PropTypes.object,
  17. };
  18. static propTypes = {
  19. status: ImmutablePropTypes.map.isRequired,
  20. onOpenMedia: PropTypes.func.isRequired,
  21. onOpenVideo: PropTypes.func.isRequired,
  22. autoPlayGif: PropTypes.bool,
  23. };
  24. handleAccountClick = (e) => {
  25. if (e.button === 0) {
  26. e.preventDefault();
  27. this.context.router.history.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
  28. }
  29. e.stopPropagation();
  30. }
  31. handleOpenVideo = startTime => {
  32. this.props.onOpenVideo(this.props.status.getIn(['media_attachments', 0]), startTime);
  33. }
  34. render () {
  35. const status = this.props.status.get('reblog') ? this.props.status.get('reblog') : this.props.status;
  36. let media = '';
  37. let applicationLink = '';
  38. let reblogLink = '';
  39. let reblogIcon = 'retweet';
  40. if (status.get('media_attachments').size > 0) {
  41. if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
  42. media = <AttachmentList media={status.get('media_attachments')} />;
  43. } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  44. const video = status.getIn(['media_attachments', 0]);
  45. media = (
  46. <Video
  47. preview={video.get('preview_url')}
  48. src={video.get('url')}
  49. width={300}
  50. height={150}
  51. onOpenVideo={this.handleOpenVideo}
  52. sensitive={status.get('sensitive')}
  53. />
  54. );
  55. } else {
  56. media = (
  57. <MediaGallery
  58. standalone
  59. sensitive={status.get('sensitive')}
  60. media={status.get('media_attachments')}
  61. height={300}
  62. onOpenMedia={this.props.onOpenMedia}
  63. autoPlayGif={this.props.autoPlayGif}
  64. />
  65. );
  66. }
  67. } else if (status.get('spoiler_text').length === 0) {
  68. media = <CardContainer statusId={status.get('id')} />;
  69. }
  70. if (status.get('application')) {
  71. applicationLink = <span> · <a className='detailed-status__application' href={status.getIn(['application', 'website'])} target='_blank' rel='noopener'>{status.getIn(['application', 'name'])}</a></span>;
  72. }
  73. if (status.get('visibility') === 'direct') {
  74. reblogIcon = 'envelope';
  75. } else if (status.get('visibility') === 'private') {
  76. reblogIcon = 'lock';
  77. }
  78. if (status.get('visibility') === 'private') {
  79. reblogLink = <i className={`fa fa-${reblogIcon}`} />;
  80. } else {
  81. reblogLink = (<Link to={`/statuses/${status.get('id')}/reblogs`} className='detailed-status__link'>
  82. <i className={`fa fa-${reblogIcon}`} />
  83. <span className='detailed-status__reblogs'>
  84. <FormattedNumber value={status.get('reblogs_count')} />
  85. </span>
  86. </Link>);
  87. }
  88. return (
  89. <div className='detailed-status'>
  90. <a href={status.getIn(['account', 'url'])} onClick={this.handleAccountClick} className='detailed-status__display-name'>
  91. <div className='detailed-status__display-avatar'><Avatar account={status.get('account')} size={48} /></div>
  92. <DisplayName account={status.get('account')} />
  93. </a>
  94. <StatusContent status={status} />
  95. {media}
  96. <div className='detailed-status__meta'>
  97. <a className='detailed-status__datetime' href={status.get('url')} target='_blank' rel='noopener'>
  98. <FormattedDate value={new Date(status.get('created_at'))} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' />
  99. </a>{applicationLink} · {reblogLink} · <Link to={`/statuses/${status.get('id')}/favourites`} className='detailed-status__link'>
  100. <i className='fa fa-star' />
  101. <span className='detailed-status__favorites'>
  102. <FormattedNumber value={status.get('favourites_count')} />
  103. </span>
  104. </Link>
  105. </div>
  106. </div>
  107. );
  108. }
  109. }