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.

98 lines
2.9 KiB

  1. // Package imports.
  2. import React from 'react';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import PropTypes from 'prop-types';
  5. import { FormattedMessage } from 'react-intl';
  6. import ImmutablePureComponent from 'react-immutable-pure-component';
  7. import { HotKeys } from 'react-hotkeys';
  8. // Our imports.
  9. import Permalink from 'flavours/glitch/components/permalink';
  10. import AccountContainer from 'flavours/glitch/containers/account_container';
  11. import NotificationOverlayContainer from '../containers/overlay_container';
  12. export default class NotificationFollow extends ImmutablePureComponent {
  13. static propTypes = {
  14. hidden: PropTypes.bool,
  15. id: PropTypes.string.isRequired,
  16. account: ImmutablePropTypes.map.isRequired,
  17. notification: ImmutablePropTypes.map.isRequired,
  18. };
  19. handleMoveUp = () => {
  20. const { notification, onMoveUp } = this.props;
  21. onMoveUp(notification.get('id'));
  22. }
  23. handleMoveDown = () => {
  24. const { notification, onMoveDown } = this.props;
  25. onMoveDown(notification.get('id'));
  26. }
  27. handleOpen = () => {
  28. this.handleOpenProfile();
  29. }
  30. handleOpenProfile = () => {
  31. const { notification } = this.props;
  32. this.context.router.history.push(`/accounts/${notification.getIn(['account', 'id'])}`);
  33. }
  34. handleMention = e => {
  35. e.preventDefault();
  36. const { notification, onMention } = this.props;
  37. onMention(notification.get('account'), this.context.router.history);
  38. }
  39. getHandlers () {
  40. return {
  41. moveUp: this.handleMoveUp,
  42. moveDown: this.handleMoveDown,
  43. open: this.handleOpen,
  44. openProfile: this.handleOpenProfile,
  45. mention: this.handleMention,
  46. reply: this.handleMention,
  47. };
  48. }
  49. render () {
  50. const { account, notification, hidden } = this.props;
  51. // Links to the display name.
  52. const displayName = account.get('display_name_html') || account.get('username');
  53. const link = (
  54. <bdi><Permalink
  55. className='notification__display-name'
  56. href={account.get('url')}
  57. title={account.get('acct')}
  58. to={`/accounts/${account.get('id')}`}
  59. dangerouslySetInnerHTML={{ __html: displayName }}
  60. /></bdi>
  61. );
  62. // Renders.
  63. return (
  64. <HotKeys handlers={this.getHandlers()}>
  65. <div className='notification notification-follow focusable' tabIndex='0'>
  66. <div className='notification__message'>
  67. <div className='notification__favourite-icon-wrapper'>
  68. <i className='fa fa-fw fa-user-plus' />
  69. </div>
  70. <FormattedMessage
  71. id='notification.follow'
  72. defaultMessage='{name} followed you'
  73. values={{ name: link }}
  74. />
  75. </div>
  76. <AccountContainer hidden={hidden} id={account.get('id')} withNote={false} />
  77. <NotificationOverlayContainer notification={notification} />
  78. </div>
  79. </HotKeys>
  80. );
  81. }
  82. }