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.
 
 
 
 

120 lines
4.3 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 '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. me: React.PropTypes.number,
  34. muted: React.PropTypes.bool
  35. },
  36. mixins: [PureRenderMixin],
  37. handleClick () {
  38. const { status } = this.props;
  39. this.context.router.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  40. },
  41. handleAccountClick (id, e) {
  42. if (e.button === 0) {
  43. e.preventDefault();
  44. this.context.router.push(`/accounts/${id}`);
  45. }
  46. },
  47. render () {
  48. let media = '';
  49. const { status, now, ...other } = this.props;
  50. if (status === null) {
  51. return <div />;
  52. }
  53. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  54. let displayName = status.getIn(['account', 'display_name']);
  55. if (displayName.length === 0) {
  56. displayName = status.getIn(['account', 'username']);
  57. }
  58. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  59. return (
  60. <div style={{ cursor: 'default' }}>
  61. <div style={{ marginLeft: '68px', color: '#616b86', padding: '8px 0', paddingBottom: '2px', fontSize: '14px', position: 'relative' }}>
  62. <div style={{ position: 'absolute', 'left': '-26px'}}><i className='fa fa-fw fa-retweet'></i></div>
  63. <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> }} />
  64. </div>
  65. <Status {...other} wrapped={true} status={status.get('reblog')} />
  66. </div>
  67. );
  68. }
  69. if (status.get('media_attachments').size > 0) {
  70. if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  71. media = <VideoPlayer media={status.getIn(['media_attachments', 0])} />;
  72. } else {
  73. media = <MediaGallery media={status.get('media_attachments')} height={110} onOpenMedia={this.props.onOpenMedia} />;
  74. }
  75. }
  76. return (
  77. <div className={this.props.muted ? 'muted' : ''} style={outerStyle}>
  78. <div style={{ fontSize: '15px' }}>
  79. <div style={{ float: 'right', fontSize: '14px' }}>
  80. <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>
  81. </div>
  82. <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' }}>
  83. <div className='status__avatar' style={{ position: 'absolute', left: '10px', top: '10px', width: '48px', height: '48px' }}>
  84. <Avatar src={status.getIn(['account', 'avatar'])} size={48} />
  85. </div>
  86. <DisplayName account={status.get('account')} />
  87. </a>
  88. </div>
  89. <StatusContent status={status} onClick={this.handleClick} />
  90. {media}
  91. <StatusActionBar {...this.props} />
  92. </div>
  93. );
  94. }
  95. });
  96. export default Status;