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

88 lines
3.2 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import StatusContainer from '../../../containers/status_container';
  4. import AccountContainer from '../../../containers/account_container';
  5. import { FormattedMessage } from 'react-intl';
  6. import Permalink from '../../../components/permalink';
  7. import emojify from '../../../emoji';
  8. import escapeTextContentForBrowser from 'escape-html';
  9. import ImmutablePureComponent from 'react-immutable-pure-component';
  10. export default class Notification extends ImmutablePureComponent {
  11. static propTypes = {
  12. notification: ImmutablePropTypes.map.isRequired,
  13. };
  14. renderFollow (account, link) {
  15. return (
  16. <div className='notification notification-follow'>
  17. <div className='notification__message'>
  18. <div className='notification__favourite-icon-wrapper'>
  19. <i className='fa fa-fw fa-user-plus' />
  20. </div>
  21. <FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
  22. </div>
  23. <AccountContainer id={account.get('id')} withNote={false} />
  24. </div>
  25. );
  26. }
  27. renderMention (notification) {
  28. return <StatusContainer id={notification.get('status')} withDismiss />;
  29. }
  30. renderFavourite (notification, link) {
  31. return (
  32. <div className='notification notification-favourite'>
  33. <div className='notification__message'>
  34. <div className='notification__favourite-icon-wrapper'>
  35. <i className='fa fa-fw fa-star star-icon' />
  36. </div>
  37. <FormattedMessage id='notification.favourite' defaultMessage='{name} favourited your status' values={{ name: link }} />
  38. </div>
  39. <StatusContainer id={notification.get('status')} account={notification.get('account')} muted withDismiss />
  40. </div>
  41. );
  42. }
  43. renderReblog (notification, link) {
  44. return (
  45. <div className='notification notification-reblog'>
  46. <div className='notification__message'>
  47. <div className='notification__favourite-icon-wrapper'>
  48. <i className='fa fa-fw fa-retweet' />
  49. </div>
  50. <FormattedMessage id='notification.reblog' defaultMessage='{name} boosted your status' values={{ name: link }} />
  51. </div>
  52. <StatusContainer id={notification.get('status')} account={notification.get('account')} muted withDismiss />
  53. </div>
  54. );
  55. }
  56. render () {
  57. const { notification } = this.props;
  58. const account = notification.get('account');
  59. const displayName = account.get('display_name').length > 0 ? account.get('display_name') : account.get('username');
  60. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  61. const link = <Permalink className='notification__display-name' href={account.get('url')} title={account.get('acct')} to={`/accounts/${account.get('id')}`} dangerouslySetInnerHTML={displayNameHTML} />;
  62. switch(notification.get('type')) {
  63. case 'follow':
  64. return this.renderFollow(account, link);
  65. case 'mention':
  66. return this.renderMention(notification);
  67. case 'favourite':
  68. return this.renderFavourite(notification, link);
  69. case 'reblog':
  70. return this.renderReblog(notification, link);
  71. }
  72. return null;
  73. }
  74. }