account_container.jsx 2.2 KB

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