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.1 KiB

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