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.

121 lines
4.3 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import PropTypes from 'prop-types';
  3. import Avatar from './avatar';
  4. import RelativeTimestamp from './relative_timestamp';
  5. import DisplayName from './display_name';
  6. import MediaGallery from './media_gallery';
  7. import VideoPlayer from './video_player';
  8. import AttachmentList from './attachment_list';
  9. import StatusContent from './status_content';
  10. import StatusActionBar from './status_action_bar';
  11. import { FormattedMessage } from 'react-intl';
  12. import emojify from '../emoji';
  13. import escapeTextContentForBrowser from 'escape-html';
  14. class Status extends React.PureComponent {
  15. constructor (props, context) {
  16. super(props, context);
  17. this.handleClick = this.handleClick.bind(this);
  18. this.handleAccountClick = this.handleAccountClick.bind(this);
  19. }
  20. handleClick () {
  21. const { status } = this.props;
  22. this.context.router.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  23. }
  24. handleAccountClick (id, e) {
  25. if (e.button === 0) {
  26. e.preventDefault();
  27. this.context.router.push(`/accounts/${id}`);
  28. }
  29. }
  30. render () {
  31. let media = '';
  32. const { status, ...other } = this.props;
  33. if (status === null) {
  34. return <div />;
  35. }
  36. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  37. let displayName = status.getIn(['account', 'display_name']);
  38. if (displayName.length === 0) {
  39. displayName = status.getIn(['account', 'username']);
  40. }
  41. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  42. return (
  43. <div className='status__wrapper'>
  44. <div className='status__prepend'>
  45. <div className='status__prepend-icon-wrapper'><i className='fa fa-fw fa-retweet status__prepend-icon' /></div>
  46. <FormattedMessage id='status.reblogged_by' defaultMessage='{name} reblogged' values={{ name: <a onClick={this.handleAccountClick.bind(this, status.getIn(['account', 'id']))} href={status.getIn(['account', 'url'])} className='status__display-name muted'><strong dangerouslySetInnerHTML={displayNameHTML} /></a> }} />
  47. </div>
  48. <Status {...other} wrapped={true} status={status.get('reblog')} />
  49. </div>
  50. );
  51. }
  52. if (status.get('media_attachments').size > 0 && !this.props.muted) {
  53. if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
  54. } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  55. media = <VideoPlayer media={status.getIn(['media_attachments', 0])} sensitive={status.get('sensitive')} onOpenVideo={this.props.onOpenVideo} />;
  56. } else {
  57. media = <MediaGallery media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} autoPlayGif={this.props.autoPlayGif} />;
  58. }
  59. }
  60. return (
  61. <div className={this.props.muted ? 'status muted' : 'status'}>
  62. <div className='status__info'>
  63. <div className='status__info-time'>
  64. <a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
  65. </div>
  66. <a onClick={this.handleAccountClick.bind(this, status.getIn(['account', 'id']))} href={status.getIn(['account', 'url'])} className='status__display-name'>
  67. <div className='status__avatar'>
  68. <Avatar src={status.getIn(['account', 'avatar'])} staticSrc={status.getIn(['account', 'avatar_static'])} size={48} />
  69. </div>
  70. <DisplayName account={status.get('account')} />
  71. </a>
  72. </div>
  73. <StatusContent status={status} onClick={this.handleClick} />
  74. {media}
  75. <StatusActionBar {...this.props} />
  76. </div>
  77. );
  78. }
  79. }
  80. Status.contextTypes = {
  81. router: PropTypes.object
  82. };
  83. Status.propTypes = {
  84. status: ImmutablePropTypes.map,
  85. wrapped: PropTypes.bool,
  86. onReply: PropTypes.func,
  87. onFavourite: PropTypes.func,
  88. onReblog: PropTypes.func,
  89. onDelete: PropTypes.func,
  90. onOpenMedia: PropTypes.func,
  91. onOpenVideo: PropTypes.func,
  92. onBlock: PropTypes.func,
  93. me: PropTypes.number,
  94. boostModal: PropTypes.bool,
  95. autoPlayGif: PropTypes.bool,
  96. muted: PropTypes.bool
  97. };
  98. export default Status;