logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

header_container.js (2970B)


  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. unmuteAccount,
  11. } from '../../../actions/accounts';
  12. import {
  13. mentionCompose,
  14. directCompose,
  15. } from '../../../actions/compose';
  16. import { initMuteModal } from '../../../actions/mutes';
  17. import { openModal } from '../../../actions/modal';
  18. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  19. import { unfollowModal } from '../../../initial_state';
  20. const messages = defineMessages({
  21. unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' },
  22. blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' },
  23. });
  24. const makeMapStateToProps = () => {
  25. const getAccount = makeGetAccount();
  26. const mapStateToProps = (state, { accountId }) => ({
  27. account: getAccount(state, accountId),
  28. });
  29. return mapStateToProps;
  30. };
  31. const mapDispatchToProps = (dispatch, { intl }) => ({
  32. onFollow (account) {
  33. if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
  34. if (unfollowModal) {
  35. dispatch(openModal('CONFIRM', {
  36. message: <FormattedMessage id='confirmations.unfollow.message' defaultMessage='Are you sure you want to unfollow {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  37. confirm: intl.formatMessage(messages.unfollowConfirm),
  38. onConfirm: () => dispatch(unfollowAccount(account.get('id'))),
  39. }));
  40. } else {
  41. dispatch(unfollowAccount(account.get('id')));
  42. }
  43. } else {
  44. dispatch(followAccount(account.get('id')));
  45. }
  46. },
  47. onBlock (account) {
  48. if (account.getIn(['relationship', 'blocking'])) {
  49. dispatch(unblockAccount(account.get('id')));
  50. } else {
  51. dispatch(openModal('CONFIRM', {
  52. message: <FormattedMessage id='confirmations.block.message' defaultMessage='Are you sure you want to block {name}?' values={{ name: <strong>@{account.get('acct')}</strong> }} />,
  53. confirm: intl.formatMessage(messages.blockConfirm),
  54. onConfirm: () => dispatch(blockAccount(account.get('id'))),
  55. }));
  56. }
  57. },
  58. onMention (account, router) {
  59. dispatch(mentionCompose(account, router));
  60. },
  61. onDirect (account, router) {
  62. dispatch(directCompose(account, router));
  63. },
  64. onReblogToggle (account) {
  65. if (account.getIn(['relationship', 'showing_reblogs'])) {
  66. dispatch(followAccount(account.get('id'), false));
  67. } else {
  68. dispatch(followAccount(account.get('id'), true));
  69. }
  70. },
  71. onMute (account) {
  72. if (account.getIn(['relationship', 'muting'])) {
  73. dispatch(unmuteAccount(account.get('id')));
  74. } else {
  75. dispatch(initMuteModal(account));
  76. }
  77. }
  78. });
  79. export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Header));