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.

94 lines
4.0 KiB

  1. import PropTypes from 'prop-types';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import Avatar from '../../../components/avatar';
  4. import DisplayName from '../../../components/display_name';
  5. import StatusContent from '../../../components/status_content';
  6. import MediaGallery from '../../../components/media_gallery';
  7. import VideoPlayer from '../../../components/video_player';
  8. import AttachmentList from '../../../components/attachment_list';
  9. import { Link } from 'react-router';
  10. import { FormattedDate, FormattedNumber } from 'react-intl';
  11. import CardContainer from '../containers/card_container';
  12. class DetailedStatus extends React.PureComponent {
  13. constructor (props, context) {
  14. super(props, context);
  15. this.handleAccountClick = this.handleAccountClick.bind(this);
  16. }
  17. handleAccountClick (e) {
  18. if (e.button === 0) {
  19. e.preventDefault();
  20. this.context.router.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
  21. }
  22. e.stopPropagation();
  23. }
  24. render () {
  25. const status = this.props.status.get('reblog') ? this.props.status.get('reblog') : this.props.status;
  26. let media = '';
  27. let applicationLink = '';
  28. if (status.get('media_attachments').size > 0) {
  29. if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
  30. media = <AttachmentList media={status.get('media_attachments')} />;
  31. } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  32. media = <VideoPlayer sensitive={status.get('sensitive')} media={status.getIn(['media_attachments', 0])} width={300} height={150} onOpenVideo={this.props.onOpenVideo} autoplay />;
  33. } else {
  34. media = <MediaGallery sensitive={status.get('sensitive')} media={status.get('media_attachments')} height={300} onOpenMedia={this.props.onOpenMedia} autoPlayGif={this.props.autoPlayGif} />;
  35. }
  36. } else if (status.get('spoiler_text').length === 0) {
  37. media = <CardContainer statusId={status.get('id')} />;
  38. }
  39. if (status.get('application')) {
  40. applicationLink = <span> · <a className='detailed-status__application' href={status.getIn(['application', 'website'])} target='_blank' rel='nooopener'>{status.getIn(['application', 'name'])}</a></span>;
  41. }
  42. return (
  43. <div className='detailed-status'>
  44. <a href={status.getIn(['account', 'url'])} onClick={this.handleAccountClick} className='detailed-status__display-name'>
  45. <div className='detailed-status__display-avatar'><Avatar src={status.getIn(['account', 'avatar'])} staticSrc={status.getIn(['account', 'avatar_static'])} size={48} /></div>
  46. <DisplayName account={status.get('account')} />
  47. </a>
  48. <StatusContent status={status} />
  49. {media}
  50. <div className='detailed-status__meta'>
  51. <a className='detailed-status__datetime' href={status.get('url')} target='_blank' rel='noopener'>
  52. <FormattedDate value={new Date(status.get('created_at'))} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' />
  53. </a>{applicationLink} · <Link to={`/statuses/${status.get('id')}/reblogs`} className='detailed-status__link'>
  54. <i className='fa fa-retweet' />
  55. <span className='detailed-status__reblogs'>
  56. <FormattedNumber value={status.get('reblogs_count')} />
  57. </span>
  58. </Link> · <Link to={`/statuses/${status.get('id')}/favourites`} className='detailed-status__link'>
  59. <i className='fa fa-star' />
  60. <span className='detailed-status__favorites'>
  61. <FormattedNumber value={status.get('favourites_count')} />
  62. </span>
  63. </Link>
  64. </div>
  65. </div>
  66. );
  67. }
  68. }
  69. DetailedStatus.contextTypes = {
  70. router: PropTypes.object
  71. };
  72. DetailedStatus.propTypes = {
  73. status: ImmutablePropTypes.map.isRequired,
  74. onOpenMedia: PropTypes.func.isRequired,
  75. onOpenVideo: PropTypes.func.isRequired,
  76. autoPlayGif: PropTypes.bool,
  77. };
  78. export default DetailedStatus;