闭社主体 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.

117 lines
2.8 KiB

  1. import api, { getLinks } from '../api';
  2. export const DOMAIN_BLOCK_REQUEST = 'DOMAIN_BLOCK_REQUEST';
  3. export const DOMAIN_BLOCK_SUCCESS = 'DOMAIN_BLOCK_SUCCESS';
  4. export const DOMAIN_BLOCK_FAIL = 'DOMAIN_BLOCK_FAIL';
  5. export const DOMAIN_UNBLOCK_REQUEST = 'DOMAIN_UNBLOCK_REQUEST';
  6. export const DOMAIN_UNBLOCK_SUCCESS = 'DOMAIN_UNBLOCK_SUCCESS';
  7. export const DOMAIN_UNBLOCK_FAIL = 'DOMAIN_UNBLOCK_FAIL';
  8. export const DOMAIN_BLOCKS_FETCH_REQUEST = 'DOMAIN_BLOCKS_FETCH_REQUEST';
  9. export const DOMAIN_BLOCKS_FETCH_SUCCESS = 'DOMAIN_BLOCKS_FETCH_SUCCESS';
  10. export const DOMAIN_BLOCKS_FETCH_FAIL = 'DOMAIN_BLOCKS_FETCH_FAIL';
  11. export function blockDomain(domain, accountId) {
  12. return (dispatch, getState) => {
  13. dispatch(blockDomainRequest(domain));
  14. api(getState).post('/api/v1/domain_blocks', { domain }).then(() => {
  15. dispatch(blockDomainSuccess(domain, accountId));
  16. }).catch(err => {
  17. dispatch(blockDomainFail(domain, err));
  18. });
  19. };
  20. };
  21. export function blockDomainRequest(domain) {
  22. return {
  23. type: DOMAIN_BLOCK_REQUEST,
  24. domain,
  25. };
  26. };
  27. export function blockDomainSuccess(domain, accountId) {
  28. return {
  29. type: DOMAIN_BLOCK_SUCCESS,
  30. domain,
  31. accountId,
  32. };
  33. };
  34. export function blockDomainFail(domain, error) {
  35. return {
  36. type: DOMAIN_BLOCK_FAIL,
  37. domain,
  38. error,
  39. };
  40. };
  41. export function unblockDomain(domain, accountId) {
  42. return (dispatch, getState) => {
  43. dispatch(unblockDomainRequest(domain));
  44. api(getState).delete('/api/v1/domain_blocks', { params: { domain } }).then(() => {
  45. dispatch(unblockDomainSuccess(domain, accountId));
  46. }).catch(err => {
  47. dispatch(unblockDomainFail(domain, err));
  48. });
  49. };
  50. };
  51. export function unblockDomainRequest(domain) {
  52. return {
  53. type: DOMAIN_UNBLOCK_REQUEST,
  54. domain,
  55. };
  56. };
  57. export function unblockDomainSuccess(domain, accountId) {
  58. return {
  59. type: DOMAIN_UNBLOCK_SUCCESS,
  60. domain,
  61. accountId,
  62. };
  63. };
  64. export function unblockDomainFail(domain, error) {
  65. return {
  66. type: DOMAIN_UNBLOCK_FAIL,
  67. domain,
  68. error,
  69. };
  70. };
  71. export function fetchDomainBlocks() {
  72. return (dispatch, getState) => {
  73. dispatch(fetchDomainBlocksRequest());
  74. api(getState).get().then(response => {
  75. const next = getLinks(response).refs.find(link => link.rel === 'next');
  76. dispatch(fetchDomainBlocksSuccess(response.data, next ? next.uri : null));
  77. }).catch(err => {
  78. dispatch(fetchDomainBlocksFail(err));
  79. });
  80. };
  81. };
  82. export function fetchDomainBlocksRequest() {
  83. return {
  84. type: DOMAIN_BLOCKS_FETCH_REQUEST,
  85. };
  86. };
  87. export function fetchDomainBlocksSuccess(domains, next) {
  88. return {
  89. type: DOMAIN_BLOCKS_FETCH_SUCCESS,
  90. domains,
  91. next,
  92. };
  93. };
  94. export function fetchDomainBlocksFail(error) {
  95. return {
  96. type: DOMAIN_BLOCKS_FETCH_FAIL,
  97. error,
  98. };
  99. };