闭社主体 forked from https://github.com/tootsuite/mastodon
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.

132 lines
4.7 KiB

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