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.

75 lines
2.4 KiB

  1. import { connect } from 'react-redux';
  2. import { makeGetAccount } from '../../../selectors';
  3. import Header from '../components/header';
  4. import {
  5. followAccount,
  6. unfollowAccount,
  7. blockAccount,
  8. unblockAccount,
  9. muteAccount,
  10. unmuteAccount
  11. } from '../../../actions/accounts';
  12. import { mentionCompose } from '../../../actions/compose';
  13. import { initReport } from '../../../actions/reports';
  14. import { openModal } from '../../../actions/modal';
  15. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  16. const messages = defineMessages({
  17. blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
  18. muteConfirm: { id: 'confirmations.mute.confirm', defaultMessage: 'Mute' }
  19. });
  20. const makeMapStateToProps = () => {
  21. const getAccount = makeGetAccount();
  22. const mapStateToProps = (state, { accountId }) => ({
  23. account: getAccount(state, Number(accountId)),
  24. me: state.getIn(['meta', 'me'])
  25. });
  26. return mapStateToProps;
  27. };
  28. const mapDispatchToProps = (dispatch, { intl }) => ({
  29. onFollow (account) {
  30. if (account.getIn(['relationship', 'following'])) {
  31. dispatch(unfollowAccount(account.get('id')));
  32. } else {
  33. dispatch(followAccount(account.get('id')));
  34. }
  35. },
  36. onBlock (account) {
  37. if (account.getIn(['relationship', 'blocking'])) {
  38. dispatch(unblockAccount(account.get('id')));
  39. } else {
  40. dispatch(openModal('CONFIRM', {
  41. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  42. confirm: intl.formatMessage(messages.blockConfirm),
  43. onConfirm: () => dispatch(blockAccount(account.get('id')))
  44. }));
  45. }
  46. },
  47. onMention (account, router) {
  48. dispatch(mentionCompose(account, router));
  49. },
  50. onReport (account) {
  51. dispatch(initReport(account));
  52. },
  53. onMute (account) {
  54. if (account.getIn(['relationship', 'muting'])) {
  55. dispatch(unmuteAccount(account.get('id')));
  56. } else {
  57. dispatch(openModal('CONFIRM', {
  58. message: <FormattedMessage id='confirmations.mute.message' defaultMessage='Are you sure you want to mute {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  59. confirm: intl.formatMessage(messages.muteConfirm),
  60. onConfirm: () => dispatch(muteAccount(account.get('id')))
  61. }));
  62. }
  63. }
  64. });
  65. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Header));