The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

112 lines
4.2 KiB

  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 'escape-html';
  13. const Status = React.createClass({
  14. contextTypes: {
  15. router: React.PropTypes.object
  16. },
  17. propTypes: {
  18. status: ImmutablePropTypes.map,
  19. wrapped: React.PropTypes.bool,
  20. onReply: React.PropTypes.func,
  21. onFavourite: React.PropTypes.func,
  22. onReblog: React.PropTypes.func,
  23. onDelete: React.PropTypes.func,
  24. onOpenMedia: React.PropTypes.func,
  25. onBlock: React.PropTypes.func,
  26. me: React.PropTypes.number,
  27. muted: React.PropTypes.bool
  28. },
  29. mixins: [PureRenderMixin],
  30. handleClick () {
  31. const { status } = this.props;
  32. this.context.router.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  33. },
  34. handleAccountClick (id, e) {
  35. if (e.button === 0) {
  36. e.preventDefault();
  37. this.context.router.push(`/accounts/${id}`);
  38. }
  39. },
  40. render () {
  41. let media = '';
  42. const { status, ...other } = this.props;
  43. if (status === null) {
  44. return <div />;
  45. }
  46. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  47. let displayName = status.getIn(['account', 'display_name']);
  48. if (displayName.length === 0) {
  49. displayName = status.getIn(['account', 'username']);
  50. }
  51. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  52. return (
  53. <div style={{ cursor: 'default' }}>
  54. <div className='status__prepend'>
  55. <div style={{ position: 'absolute', 'left': '-26px'}}><i className='fa fa-fw fa-retweet' /></div>
  56. <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> }} />
  57. </div>
  58. <Status {...other} wrapped={true} status={status.get('reblog')} />
  59. </div>
  60. );
  61. }
  62. if (status.get('media_attachments').size > 0 && !this.props.muted) {
  63. if (status.getIn(['media_attachments', 0, 'type']) === 'video' || (status.get('media_attachments').size === 1 && status.getIn(['media_attachments', 0, 'type']) === 'gifv')) {
  64. media = <VideoPlayer media={status.getIn(['media_attachments', 0])} autoplay={status.getIn(['media_attachments', 0, 'type']) === 'gifv'} sensitive={status.get('sensitive')} />;
  65. } else {
  66. media = <MediaGallery media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} />;
  67. }
  68. }
  69. return (
  70. <div className={this.props.muted ? 'status muted' : 'status'}>
  71. <div style={{ fontSize: '15px' }}>
  72. <div style={{ float: 'right', fontSize: '14px' }}>
  73. <a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
  74. </div>
  75. <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' }}>
  76. <div className='status__avatar' style={{ position: 'absolute', left: '10px', top: '10px', width: '48px', height: '48px' }}>
  77. <Avatar src={status.getIn(['account', 'avatar'])} size={48} />
  78. </div>
  79. <DisplayName account={status.get('account')} />
  80. </a>
  81. </div>
  82. <StatusContent status={status} onClick={this.handleClick} />
  83. {media}
  84. <StatusActionBar {...this.props} />
  85. </div>
  86. );
  87. }
  88. });
  89. export default Status;