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.

82 lines
4.1 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' style={{ color: 'inherit' }} href={status.getIn(['application', 'website'])} target='_blank' rel='nooopener'>{status.getIn(['application', 'name'])}</a></span>;
  41. }
  42. return (
  43. <div style={{ padding: '14px 10px' }} className='detailed-status'>
  44. <a href={status.getIn(['account', 'url'])} onClick={this.handleAccountClick} className='detailed-status__display-name' style={{ display: 'block', overflow: 'hidden', marginBottom: '15px' }}>
  45. <div style={{ float: 'left', marginRight: '10px' }}><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' style={{ color: 'inherit' }} href={status.get('url')} target='_blank' rel='noopener'><FormattedDate value={new Date(status.get('created_at'))} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' /></a>{applicationLink} · <Link to={`/statuses/${status.get('id')}/reblogs`} style={{ color: 'inherit', textDecoration: 'none' }}><i className='fa fa-retweet' /><span style={{ fontWeight: '500', fontSize: '12px', marginLeft: '6px', display: 'inline-block' }}><FormattedNumber value={status.get('reblogs_count')} /></span></Link> · <Link to={`/statuses/${status.get('id')}/favourites`} style={{ color: 'inherit', textDecoration: 'none' }}><i className='fa fa-star' /><span style={{ fontWeight: '500', fontSize: '12px', marginLeft: '6px', display: 'inline-block' }}><FormattedNumber value={status.get('favourites_count')} /></span></Link>
  52. </div>
  53. </div>
  54. );
  55. }
  56. }
  57. DetailedStatus.contextTypes = {
  58. router: PropTypes.object
  59. };
  60. DetailedStatus.propTypes = {
  61. status: ImmutablePropTypes.map.isRequired,
  62. onOpenMedia: PropTypes.func.isRequired,
  63. onOpenVideo: PropTypes.func.isRequired,
  64. autoPlayGif: PropTypes.bool,
  65. };
  66. export default DetailedStatus;