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.

123 lines
4.3 KiB

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