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.

130 lines
5.1 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import Avatar from 'flavours/glitch/components/avatar';
  5. import DisplayName from 'flavours/glitch/components/display_name';
  6. import StatusContent from 'flavours/glitch/components/status_content';
  7. import StatusGallery from 'flavours/glitch/components/media_gallery';
  8. import AttachmentList from 'flavours/glitch/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 'flavours/glitch/features/video';
  14. import VisibilityIcon from 'flavours/glitch/components/status_visibility_icon';
  15. export default class DetailedStatus extends ImmutablePureComponent {
  16. static contextTypes = {
  17. router: PropTypes.object,
  18. };
  19. static propTypes = {
  20. status: ImmutablePropTypes.map.isRequired,
  21. settings: ImmutablePropTypes.map.isRequired,
  22. onOpenMedia: PropTypes.func.isRequired,
  23. onOpenVideo: PropTypes.func.isRequired,
  24. };
  25. handleAccountClick = (e) => {
  26. if (e.button === 0) {
  27. e.preventDefault();
  28. this.context.router.history.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
  29. }
  30. e.stopPropagation();
  31. }
  32. // handleOpenVideo = startTime => {
  33. // this.props.onOpenVideo(this.props.status.getIn(['media_attachments', 0]), startTime);
  34. // }
  35. render () {
  36. const status = this.props.status.get('reblog') ? this.props.status.get('reblog') : this.props.status;
  37. const { expanded, setExpansion, settings } = this.props;
  38. let media = '';
  39. let mediaIcon = null;
  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. media = (
  48. <Video
  49. sensitive={status.get('sensitive')}
  50. media={status.getIn(['media_attachments', 0])}
  51. letterbox={settings.getIn(['media', 'letterbox'])}
  52. fullwidth={settings.getIn(['media', 'fullwidth'])}
  53. onOpenVideo={this.props.onOpenVideo}
  54. autoplay
  55. />
  56. );
  57. mediaIcon = 'video-camera';
  58. } else {
  59. media = (
  60. <StatusGallery
  61. sensitive={status.get('sensitive')}
  62. media={status.get('media_attachments')}
  63. letterbox={settings.getIn(['media', 'letterbox'])}
  64. onOpenMedia={this.props.onOpenMedia}
  65. />
  66. );
  67. mediaIcon = 'picture-o';
  68. }
  69. } else media = <CardContainer statusId={status.get('id')} />;
  70. if (status.get('application')) {
  71. applicationLink = <span> · <a className='detailed-status__application' href={status.getIn(['application', 'website'])} target='_blank' rel='noopener'>{status.getIn(['application', 'name'])}</a></span>;
  72. }
  73. if (status.get('visibility') === 'direct') {
  74. reblogIcon = 'envelope';
  75. } else if (status.get('visibility') === 'private') {
  76. reblogIcon = 'lock';
  77. }
  78. if (status.get('visibility') === 'private') {
  79. reblogLink = <i className={`fa fa-${reblogIcon}`} />;
  80. } else {
  81. reblogLink = (<Link to={`/statuses/${status.get('id')}/reblogs`} className='detailed-status__link'>
  82. <i className={`fa fa-${reblogIcon}`} />
  83. <span className='detailed-status__reblogs'>
  84. <FormattedNumber value={status.get('reblogs_count')} />
  85. </span>
  86. </Link>);
  87. }
  88. return (
  89. <div className='detailed-status' data-status-by={status.getIn(['account', 'acct'])}>
  90. <a href={status.getIn(['account', 'url'])} onClick={this.handleAccountClick} className='detailed-status__display-name'>
  91. <div className='detailed-status__display-avatar'><Avatar account={status.get('account')} size={48} /></div>
  92. <DisplayName account={status.get('account')} />
  93. </a>
  94. <StatusContent
  95. status={status}
  96. media={media}
  97. mediaIcon={mediaIcon}
  98. expanded={expanded}
  99. setExpansion={setExpansion}
  100. />
  101. <div className='detailed-status__meta'>
  102. <a className='detailed-status__datetime' href={status.get('url')} target='_blank' rel='noopener'>
  103. <FormattedDate value={new Date(status.get('created_at'))} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' />
  104. </a>{applicationLink} · {reblogLink} · <Link to={`/statuses/${status.get('id')}/favourites`} className='detailed-status__link'>
  105. <i className='fa fa-star' />
  106. <span className='detailed-status__favorites'>
  107. <FormattedNumber value={status.get('favourites_count')} />
  108. </span>
  109. </Link> · <VisibilityIcon visibility={status.get('visibility')} />
  110. </div>
  111. </div>
  112. );
  113. }
  114. }