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.

171 lines
3.9 KiB

  1. /*
  2. `<NotificationFollow>`
  3. ======================
  4. This component renders a follow notification.
  5. __Props:__
  6. - __`id` (`PropTypes.number.isRequired`) :__
  7. This is the id of the notification.
  8. - __`onDeleteNotification` (`PropTypes.func.isRequired`) :__
  9. The function to call when a notification should be
  10. dismissed/deleted.
  11. - __`account` (`PropTypes.object.isRequired`) :__
  12. The account associated with the follow notification, ie the account
  13. which followed the user.
  14. - __`intl` (`PropTypes.object.isRequired`) :__
  15. Our internationalization object, inserted by `@injectIntl`.
  16. */
  17. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  18. /*
  19. Imports:
  20. --------
  21. */
  22. // Package imports //
  23. import React from 'react';
  24. import ImmutablePropTypes from 'react-immutable-proptypes';
  25. import PropTypes from 'prop-types';
  26. import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
  27. import escapeTextContentForBrowser from 'escape-html';
  28. import ImmutablePureComponent from 'react-immutable-pure-component';
  29. // Mastodon imports //
  30. import emojify from '../../../mastodon/emoji';
  31. import Permalink from '../../../mastodon/components/permalink';
  32. import AccountContainer from '../../../mastodon/containers/account_container';
  33. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  34. /*
  35. Inital setup:
  36. -------------
  37. The `messages` constant is used to define any messages that we need
  38. from inside props.
  39. */
  40. const messages = defineMessages({
  41. deleteNotification :
  42. { id: 'status.dismiss_notification', defaultMessage: 'Dismiss notification' },
  43. });
  44. /*
  45. Implementation:
  46. ---------------
  47. */
  48. @injectIntl
  49. export default class NotificationFollow extends ImmutablePureComponent {
  50. static propTypes = {
  51. id : PropTypes.number.isRequired,
  52. onDeleteNotification : PropTypes.func.isRequired,
  53. account : ImmutablePropTypes.map.isRequired,
  54. intl : PropTypes.object.isRequired,
  55. };
  56. /*
  57. ### `handleNotificationDeleteClick()`
  58. This function just calls our `onDeleteNotification()` prop with the
  59. notification's `id`.
  60. */
  61. handleNotificationDeleteClick = () => {
  62. this.props.onDeleteNotification(this.props.id);
  63. }
  64. /*
  65. ### `render()`
  66. This actually renders the component.
  67. */
  68. render () {
  69. const { account, intl } = this.props;
  70. /*
  71. `dismiss` creates the notification dismissal button. Its title is given
  72. by `dismissTitle`.
  73. */
  74. const dismissTitle = intl.formatMessage(messages.deleteNotification);
  75. const dismiss = (
  76. <button
  77. aria-label={dismissTitle}
  78. title={dismissTitle}
  79. onClick={this.handleNotificationDeleteClick}
  80. className='status__prepend-dismiss-button'
  81. >
  82. <i className='fa fa-eraser' />
  83. </button>
  84. );
  85. /*
  86. `link` is a container for the account's `displayName`, which links to
  87. the account timeline using a `<Permalink>`.
  88. */
  89. const displayName = account.get('display_name') || account.get('username');
  90. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  91. const link = (
  92. <Permalink
  93. className='notification__display-name'
  94. href={account.get('url')}
  95. title={account.get('acct')}
  96. to={`/accounts/${account.get('id')}`}
  97. dangerouslySetInnerHTML={displayNameHTML}
  98. />
  99. );
  100. /*
  101. We can now render our component.
  102. */
  103. return (
  104. <div className='notification notification-follow'>
  105. <div className='notification__message'>
  106. <div className='notification__favourite-icon-wrapper'>
  107. <i className='fa fa-fw fa-user-plus' />
  108. </div>
  109. <FormattedMessage
  110. id='notification.follow'
  111. defaultMessage='{name} followed you'
  112. values={{ name: link }}
  113. />
  114. {dismiss}
  115. </div>
  116. <AccountContainer id={account.get('id')} withNote={false} />
  117. </div>
  118. );
  119. }
  120. }