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.

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