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.

120 lines
4.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import Avatar from './avatar';
  3. import RelativeTimestamp from './relative_timestamp';
  4. import PureRenderMixin from 'react-addons-pure-render-mixin';
  5. import DisplayName from './display_name';
  6. import MediaGallery from './media_gallery';
  7. import VideoPlayer from './video_player';
  8. import StatusContent from './status_content';
  9. import StatusActionBar from './status_action_bar';
  10. import { FormattedMessage } from 'react-intl';
  11. import emojify from '../emoji';
  12. import escapeTextContentForBrowser from 'react/lib/escapeTextContentForBrowser';
  13. const outerStyle = {
  14. padding: '8px 10px',
  15. paddingLeft: '68px',
  16. position: 'relative',
  17. minHeight: '48px',
  18. borderBottom: '1px solid #363c4b',
  19. cursor: 'default'
  20. };
  21. const Status = React.createClass({
  22. contextTypes: {
  23. router: React.PropTypes.object
  24. },
  25. propTypes: {
  26. status: ImmutablePropTypes.map,
  27. wrapped: React.PropTypes.bool,
  28. onReply: React.PropTypes.func,
  29. onFavourite: React.PropTypes.func,
  30. onReblog: React.PropTypes.func,
  31. onDelete: React.PropTypes.func,
  32. onOpenMedia: React.PropTypes.func,
  33. onBlock: React.PropTypes.func,
  34. me: React.PropTypes.number,
  35. muted: React.PropTypes.bool
  36. },
  37. mixins: [PureRenderMixin],
  38. handleClick () {
  39. const { status } = this.props;
  40. this.context.router.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  41. },
  42. handleAccountClick (id, e) {
  43. if (e.button === 0) {
  44. e.preventDefault();
  45. this.context.router.push(`/accounts/${id}`);
  46. }
  47. },
  48. render () {
  49. let media = '';
  50. const { status, now, ...other } = this.props;
  51. if (status === null) {
  52. return <div />;
  53. }
  54. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  55. let displayName = status.getIn(['account', 'display_name']);
  56. if (displayName.length === 0) {
  57. displayName = status.getIn(['account', 'username']);
  58. }
  59. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  60. return (
  61. <div style={{ cursor: 'default' }}>
  62. <div style={{ marginLeft: '68px', color: '#616b86', padding: '8px 0', paddingBottom: '2px', fontSize: '14px', position: 'relative' }}>
  63. <div style={{ position: 'absolute', 'left': '-26px'}}><i className='fa fa-fw fa-retweet'></i></div>
  64. <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 style={{ color: '#616b86'}} dangerouslySetInnerHTML={displayNameHTML} /></a> }} />
  65. </div>
  66. <Status {...other} wrapped={true} status={status.get('reblog')} />
  67. </div>
  68. );
  69. }
  70. if (status.get('media_attachments').size > 0 && !this.props.muted) {
  71. if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  72. media = <VideoPlayer media={status.getIn(['media_attachments', 0])} sensitive={status.get('sensitive')} />;
  73. } else {
  74. media = <MediaGallery media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} />;
  75. }
  76. }
  77. return (
  78. <div className={this.props.muted ? 'muted' : ''} style={outerStyle}>
  79. <div style={{ fontSize: '15px' }}>
  80. <div style={{ float: 'right', fontSize: '14px' }}>
  81. <a href={status.get('url')} className='status__relative-time' style={{ color: '#616b86' }} target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} now={now} /></a>
  82. </div>
  83. <a onClick={this.handleAccountClick.bind(this, status.getIn(['account', 'id']))} href={status.getIn(['account', 'url'])} className='status__display-name' style={{ display: 'block', maxWidth: '100%', paddingRight: '25px', color: '#616b86' }}>
  84. <div className='status__avatar' style={{ position: 'absolute', left: '10px', top: '10px', width: '48px', height: '48px' }}>
  85. <Avatar src={status.getIn(['account', 'avatar'])} size={48} />
  86. </div>
  87. <DisplayName account={status.get('account')} />
  88. </a>
  89. </div>
  90. <StatusContent status={status} onClick={this.handleClick} />
  91. {media}
  92. <StatusActionBar {...this.props} />
  93. </div>
  94. );
  95. }
  96. });
  97. export default Status;