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.

125 lines
4.5 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. };
  23. handleAccountClick = (e) => {
  24. if (e.button === 0) {
  25. e.preventDefault();
  26. this.context.router.history.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
  27. }
  28. e.stopPropagation();
  29. }
  30. handleOpenVideo = startTime => {
  31. this.props.onOpenVideo(this.props.status.getIn(['media_attachments', 0]), startTime);
  32. }
  33. render () {
  34. const status = this.props.status.get('reblog') ? this.props.status.get('reblog') : this.props.status;
  35. let media = '';
  36. let applicationLink = '';
  37. let reblogLink = '';
  38. let reblogIcon = 'retweet';
  39. if (status.get('media_attachments').size > 0) {
  40. if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
  41. media = <AttachmentList media={status.get('media_attachments')} />;
  42. } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  43. const video = status.getIn(['media_attachments', 0]);
  44. media = (
  45. <Video
  46. preview={video.get('preview_url')}
  47. src={video.get('url')}
  48. width={300}
  49. height={150}
  50. onOpenVideo={this.handleOpenVideo}
  51. sensitive={status.get('sensitive')}
  52. />
  53. );
  54. } else {
  55. media = (
  56. <MediaGallery
  57. standalone
  58. sensitive={status.get('sensitive')}
  59. media={status.get('media_attachments')}
  60. height={300}
  61. onOpenMedia={this.props.onOpenMedia}
  62. />
  63. );
  64. }
  65. } else if (status.get('spoiler_text').length === 0) {
  66. media = <CardContainer statusId={status.get('id')} />;
  67. }
  68. if (status.get('application')) {
  69. applicationLink = <span> · <a className='detailed-status__application' href={status.getIn(['application', 'website'])} target='_blank' rel='noopener'>{status.getIn(['application', 'name'])}</a></span>;
  70. }
  71. if (status.get('visibility') === 'direct') {
  72. reblogIcon = 'envelope';
  73. } else if (status.get('visibility') === 'private') {
  74. reblogIcon = 'lock';
  75. }
  76. if (status.get('visibility') === 'private') {
  77. reblogLink = <i className={`fa fa-${reblogIcon}`} />;
  78. } else {
  79. reblogLink = (<Link to={`/statuses/${status.get('id')}/reblogs`} className='detailed-status__link'>
  80. <i className={`fa fa-${reblogIcon}`} />
  81. <span className='detailed-status__reblogs'>
  82. <FormattedNumber value={status.get('reblogs_count')} />
  83. </span>
  84. </Link>);
  85. }
  86. return (
  87. <div className='detailed-status'>
  88. <a href={status.getIn(['account', 'url'])} onClick={this.handleAccountClick} className='detailed-status__display-name'>
  89. <div className='detailed-status__display-avatar'><Avatar account={status.get('account')} size={48} /></div>
  90. <DisplayName account={status.get('account')} />
  91. </a>
  92. <StatusContent status={status} />
  93. {media}
  94. <div className='detailed-status__meta'>
  95. <a className='detailed-status__datetime' href={status.get('url')} target='_blank' rel='noopener'>
  96. <FormattedDate value={new Date(status.get('created_at'))} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' />
  97. </a>{applicationLink} · {reblogLink} · <Link to={`/statuses/${status.get('id')}/favourites`} className='detailed-status__link'>
  98. <i className='fa fa-star' />
  99. <span className='detailed-status__favorites'>
  100. <FormattedNumber value={status.get('favourites_count')} />
  101. </span>
  102. </Link>
  103. </div>
  104. </div>
  105. );
  106. }
  107. }