闭社主体 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.

125 lines
4.6 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. static contextTypes = {
  19. router: PropTypes.object,
  20. };
  21. static propTypes = {
  22. status: ImmutablePropTypes.map,
  23. account: ImmutablePropTypes.map,
  24. wrapped: PropTypes.bool,
  25. onReply: PropTypes.func,
  26. onFavourite: PropTypes.func,
  27. onReblog: PropTypes.func,
  28. onDelete: PropTypes.func,
  29. onOpenMedia: PropTypes.func,
  30. onOpenVideo: PropTypes.func,
  31. onBlock: PropTypes.func,
  32. me: PropTypes.number,
  33. boostModal: PropTypes.bool,
  34. autoPlayGif: PropTypes.bool,
  35. muted: PropTypes.bool,
  36. };
  37. handleClick = () => {
  38. const { status } = this.props;
  39. this.context.router.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  40. }
  41. handleAccountClick = (e) => {
  42. if (e.button === 0) {
  43. const id = Number(e.currentTarget.getAttribute('data-id'));
  44. e.preventDefault();
  45. this.context.router.push(`/accounts/${id}`);
  46. }
  47. }
  48. render () {
  49. let media = '';
  50. let statusAvatar;
  51. const { status, account, ...other } = this.props;
  52. if (status === null) {
  53. return <div />;
  54. }
  55. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  56. let displayName = status.getIn(['account', 'display_name']);
  57. if (displayName.length === 0) {
  58. displayName = status.getIn(['account', 'username']);
  59. }
  60. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  61. return (
  62. <div className='status__wrapper'>
  63. <div className='status__prepend'>
  64. <div className='status__prepend-icon-wrapper'><i className='fa fa-fw fa-retweet status__prepend-icon' /></div>
  65. <FormattedMessage id='status.reblogged_by' defaultMessage='{name} boosted' values={{ name: <a onClick={this.handleAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name muted'><strong dangerouslySetInnerHTML={displayNameHTML} /></a> }} />
  66. </div>
  67. <Status {...other} wrapped={true} status={status.get('reblog')} account={status.get('account')} />
  68. </div>
  69. );
  70. }
  71. if (status.get('media_attachments').size > 0 && !this.props.muted) {
  72. if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
  73. } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  74. media = <VideoPlayer media={status.getIn(['media_attachments', 0])} sensitive={status.get('sensitive')} onOpenVideo={this.props.onOpenVideo} />;
  75. } else {
  76. media = <MediaGallery media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={this.props.onOpenMedia} autoPlayGif={this.props.autoPlayGif} />;
  77. }
  78. }
  79. if (account === undefined || account === null) {
  80. statusAvatar = <Avatar src={status.getIn(['account', 'avatar'])} staticSrc={status.getIn(['account', 'avatar_static'])} size={48}/>;
  81. }else{
  82. statusAvatar = <AvatarOverlay staticSrc={status.getIn(['account', 'avatar_static'])} overlaySrc={account.get('avatar_static')} />;
  83. }
  84. return (
  85. <div className={`status ${this.props.muted ? 'muted' : ''} status-${status.get('visibility')}`}>
  86. <div className='status__info'>
  87. <a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
  88. <a onClick={this.handleAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name'>
  89. <div className='status__avatar'>
  90. {statusAvatar}
  91. </div>
  92. <DisplayName account={status.get('account')} />
  93. </a>
  94. </div>
  95. <StatusContent status={status} onClick={this.handleClick} />
  96. {media}
  97. <StatusActionBar {...this.props} />
  98. </div>
  99. );
  100. }
  101. }
  102. export default Status;