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.

102 lines
3.8 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { makeGetAccount } from '../../../selectors';
  4. import Header from '../components/header';
  5. import {
  6. followAccount,
  7. unfollowAccount,
  8. blockAccount,
  9. unblockAccount,
  10. muteAccount,
  11. unmuteAccount,
  12. } from '../../../actions/accounts';
  13. import { mentionCompose } from '../../../actions/compose';
  14. import { initReport } from '../../../actions/reports';
  15. import { openModal } from '../../../actions/modal';
  16. import { blockDomain, unblockDomain } from '../../../actions/domain_blocks';
  17. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  18. const messages = defineMessages({
  19. unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' },
  20. blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
  21. muteConfirm: { id: 'confirmations.mute.confirm', defaultMessage: 'Mute' },
  22. blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Hide entire domain' },
  23. });
  24. const makeMapStateToProps = () => {
  25. const getAccount = makeGetAccount();
  26. const mapStateToProps = (state, { accountId }) => ({
  27. account: getAccount(state, Number(accountId)),
  28. me: state.getIn(['meta', 'me']),
  29. unfollowModal: state.getIn(['meta', 'unfollow_modal']),
  30. });
  31. return mapStateToProps;
  32. };
  33. const mapDispatchToProps = (dispatch, { intl }) => ({
  34. onFollow (account) {
  35. if (account.getIn(['relationship', 'following'])) {
  36. if (this.unfollowModal) {
  37. dispatch(openModal('CONFIRM', {
  38. message: <FormattedMessage id='confirmations.unfollow.message' defaultMessage='Are you sure you want to unfollow {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  39. confirm: intl.formatMessage(messages.unfollowConfirm),
  40. onConfirm: () => dispatch(unfollowAccount(account.get('id'))),
  41. }));
  42. } else {
  43. dispatch(unfollowAccount(account.get('id')));
  44. }
  45. } else {
  46. dispatch(followAccount(account.get('id')));
  47. }
  48. },
  49. onBlock (account) {
  50. if (account.getIn(['relationship', 'blocking'])) {
  51. dispatch(unblockAccount(account.get('id')));
  52. } else {
  53. dispatch(openModal('CONFIRM', {
  54. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  55. confirm: intl.formatMessage(messages.blockConfirm),
  56. onConfirm: () => dispatch(blockAccount(account.get('id'))),
  57. }));
  58. }
  59. },
  60. onMention (account, router) {
  61. dispatch(mentionCompose(account, router));
  62. },
  63. onReport (account) {
  64. dispatch(initReport(account));
  65. },
  66. onMute (account) {
  67. if (account.getIn(['relationship', 'muting'])) {
  68. dispatch(unmuteAccount(account.get('id')));
  69. } else {
  70. dispatch(openModal('CONFIRM', {
  71. message: <FormattedMessage id='confirmations.mute.message' defaultMessage='Are you sure you want to mute {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  72. confirm: intl.formatMessage(messages.muteConfirm),
  73. onConfirm: () => dispatch(muteAccount(account.get('id'))),
  74. }));
  75. }
  76. },
  77. onBlockDomain (domain, accountId) {
  78. dispatch(openModal('CONFIRM', {
  79. message: <FormattedMessage id='confirmations.domain_block.message' defaultMessage='Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.' values={{ domain: <strong>{domain}</strong> }} />,
  80. confirm: intl.formatMessage(messages.blockDomainConfirm),
  81. onConfirm: () => dispatch(blockDomain(domain, accountId)),
  82. }));
  83. },
  84. onUnblockDomain (domain, accountId) {
  85. dispatch(unblockDomain(domain, accountId));
  86. },
  87. });
  88. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Header));