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.

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