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.

95 lines
3.2 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  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. const linkStyle = {
  10. fontWeight: '500'
  11. };
  12. const Notification = React.createClass({
  13. propTypes: {
  14. notification: ImmutablePropTypes.map.isRequired
  15. },
  16. mixins: [PureRenderMixin],
  17. renderFollow (account, link) {
  18. return (
  19. <div className='notification notification-follow'>
  20. <div className='notification__message'>
  21. <div style={{ position: 'absolute', 'left': '-26px'}}>
  22. <i className='fa fa-fw fa-user-plus' />
  23. </div>
  24. <FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
  25. </div>
  26. <AccountContainer id={account.get('id')} withNote={false} />
  27. </div>
  28. );
  29. },
  30. renderMention (notification) {
  31. return <StatusContainer id={notification.get('status')} />;
  32. },
  33. renderFavourite (notification, link) {
  34. return (
  35. <div className='notification notification-favourite'>
  36. <div className='notification__message'>
  37. <div style={{ position: 'absolute', 'left': '-26px'}}>
  38. <i className='fa fa-fw fa-star' style={{ color: '#ca8f04' }} />
  39. </div>
  40. <FormattedMessage id='notification.favourite' defaultMessage='{name} favourited your status' values={{ name: link }} />
  41. </div>
  42. <StatusContainer id={notification.get('status')} muted={true} />
  43. </div>
  44. );
  45. },
  46. renderReblog (notification, link) {
  47. return (
  48. <div className='notification notification-reblog'>
  49. <div className='notification__message'>
  50. <div style={{ position: 'absolute', 'left': '-26px'}}>
  51. <i className='fa fa-fw fa-retweet' />
  52. </div>
  53. <FormattedMessage id='notification.reblog' defaultMessage='{name} boosted your status' values={{ name: link }} />
  54. </div>
  55. <StatusContainer id={notification.get('status')} muted={true} />
  56. </div>
  57. );
  58. },
  59. render () {
  60. const { notification } = this.props;
  61. const account = notification.get('account');
  62. const displayName = account.get('display_name').length > 0 ? account.get('display_name') : account.get('username');
  63. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  64. const link = <Permalink className='notification__display-name' style={linkStyle} href={account.get('url')} to={`/accounts/${account.get('id')}`} dangerouslySetInnerHTML={displayNameHTML} />;
  65. switch(notification.get('type')) {
  66. case 'follow':
  67. return this.renderFollow(account, link);
  68. case 'mention':
  69. return this.renderMention(notification);
  70. case 'favourite':
  71. return this.renderFavourite(notification, link);
  72. case 'reblog':
  73. return this.renderReblog(notification, link);
  74. }
  75. }
  76. });
  77. export default Notification;