闭社主体 forked from https://github.com/tootsuite/mastodon
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.

91 lines
3.9 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 VideoPlayer from '../../../components/video_player';
  9. import AttachmentList from '../../../components/attachment_list';
  10. import Link from 'react-router/lib/Link';
  11. import { FormattedDate, FormattedNumber } from 'react-intl';
  12. import CardContainer from '../containers/card_container';
  13. import ImmutablePureComponent from 'react-immutable-pure-component';
  14. 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.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
  28. }
  29. e.stopPropagation();
  30. }
  31. render () {
  32. const status = this.props.status.get('reblog') ? this.props.status.get('reblog') : this.props.status;
  33. let media = '';
  34. let applicationLink = '';
  35. if (status.get('media_attachments').size > 0) {
  36. if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
  37. media = <AttachmentList media={status.get('media_attachments')} />;
  38. } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  39. media = <VideoPlayer sensitive={status.get('sensitive')} media={status.getIn(['media_attachments', 0])} width={300} height={150} onOpenVideo={this.props.onOpenVideo} autoplay />;
  40. } else {
  41. media = <MediaGallery sensitive={status.get('sensitive')} media={status.get('media_attachments')} height={300} onOpenMedia={this.props.onOpenMedia} autoPlayGif={this.props.autoPlayGif} />;
  42. }
  43. } else if (status.get('spoiler_text').length === 0) {
  44. media = <CardContainer statusId={status.get('id')} />;
  45. }
  46. if (status.get('application')) {
  47. applicationLink = <span> · <a className='detailed-status__application' href={status.getIn(['application', 'website'])} target='_blank' rel='noopener'>{status.getIn(['application', 'name'])}</a></span>;
  48. }
  49. return (
  50. <div className='detailed-status'>
  51. <a href={status.getIn(['account', 'url'])} onClick={this.handleAccountClick} className='detailed-status__display-name'>
  52. <div className='detailed-status__display-avatar'><Avatar src={status.getIn(['account', 'avatar'])} staticSrc={status.getIn(['account', 'avatar_static'])} size={48} /></div>
  53. <DisplayName account={status.get('account')} />
  54. </a>
  55. <StatusContent status={status} />
  56. {media}
  57. <div className='detailed-status__meta'>
  58. <a className='detailed-status__datetime' href={status.get('url')} target='_blank' rel='noopener'>
  59. <FormattedDate value={new Date(status.get('created_at'))} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' />
  60. </a>{applicationLink} · <Link to={`/statuses/${status.get('id')}/reblogs`} className='detailed-status__link'>
  61. <i className='fa fa-retweet' />
  62. <span className='detailed-status__reblogs'>
  63. <FormattedNumber value={status.get('reblogs_count')} />
  64. </span>
  65. </Link> · <Link to={`/statuses/${status.get('id')}/favourites`} className='detailed-status__link'>
  66. <i className='fa fa-star' />
  67. <span className='detailed-status__favorites'>
  68. <FormattedNumber value={status.get('favourites_count')} />
  69. </span>
  70. </Link>
  71. </div>
  72. </div>
  73. );
  74. }
  75. }
  76. export default DetailedStatus;