闭社主体 forked from https://github.com/tootsuite/mastodon
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.

68 lines
2.0 KiB

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