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.

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