logo

mastofe

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

domain_blocks.js (4302B)


  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 const DOMAIN_BLOCKS_EXPAND_REQUEST = 'DOMAIN_BLOCKS_EXPAND_REQUEST';
  12. export const DOMAIN_BLOCKS_EXPAND_SUCCESS = 'DOMAIN_BLOCKS_EXPAND_SUCCESS';
  13. export const DOMAIN_BLOCKS_EXPAND_FAIL = 'DOMAIN_BLOCKS_EXPAND_FAIL';
  14. export function blockDomain(domain) {
  15. return (dispatch, getState) => {
  16. dispatch(blockDomainRequest(domain));
  17. api(getState).post('/api/v1/domain_blocks', { domain }).then(() => {
  18. const at_domain = '@' + domain;
  19. const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
  20. dispatch(blockDomainSuccess(domain, accounts));
  21. }).catch(err => {
  22. dispatch(blockDomainFail(domain, err));
  23. });
  24. };
  25. };
  26. export function blockDomainRequest(domain) {
  27. return {
  28. type: DOMAIN_BLOCK_REQUEST,
  29. domain,
  30. };
  31. };
  32. export function blockDomainSuccess(domain, accounts) {
  33. return {
  34. type: DOMAIN_BLOCK_SUCCESS,
  35. domain,
  36. accounts,
  37. };
  38. };
  39. export function blockDomainFail(domain, error) {
  40. return {
  41. type: DOMAIN_BLOCK_FAIL,
  42. domain,
  43. error,
  44. };
  45. };
  46. export function unblockDomain(domain) {
  47. return (dispatch, getState) => {
  48. dispatch(unblockDomainRequest(domain));
  49. api(getState).delete('/api/v1/domain_blocks', { params: { domain } }).then(() => {
  50. const at_domain = '@' + domain;
  51. const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
  52. dispatch(unblockDomainSuccess(domain, accounts));
  53. }).catch(err => {
  54. dispatch(unblockDomainFail(domain, err));
  55. });
  56. };
  57. };
  58. export function unblockDomainRequest(domain) {
  59. return {
  60. type: DOMAIN_UNBLOCK_REQUEST,
  61. domain,
  62. };
  63. };
  64. export function unblockDomainSuccess(domain, accounts) {
  65. return {
  66. type: DOMAIN_UNBLOCK_SUCCESS,
  67. domain,
  68. accounts,
  69. };
  70. };
  71. export function unblockDomainFail(domain, error) {
  72. return {
  73. type: DOMAIN_UNBLOCK_FAIL,
  74. domain,
  75. error,
  76. };
  77. };
  78. export function fetchDomainBlocks() {
  79. return (dispatch, getState) => {
  80. dispatch(fetchDomainBlocksRequest());
  81. api(getState).get('/api/v1/domain_blocks').then(response => {
  82. const next = getLinks(response).refs.find(link => link.rel === 'next');
  83. dispatch(fetchDomainBlocksSuccess(response.data, next ? next.uri : null));
  84. }).catch(err => {
  85. dispatch(fetchDomainBlocksFail(err));
  86. });
  87. };
  88. };
  89. export function fetchDomainBlocksRequest() {
  90. return {
  91. type: DOMAIN_BLOCKS_FETCH_REQUEST,
  92. };
  93. };
  94. export function fetchDomainBlocksSuccess(domains, next) {
  95. return {
  96. type: DOMAIN_BLOCKS_FETCH_SUCCESS,
  97. domains,
  98. next,
  99. };
  100. };
  101. export function fetchDomainBlocksFail(error) {
  102. return {
  103. type: DOMAIN_BLOCKS_FETCH_FAIL,
  104. error,
  105. };
  106. };
  107. export function expandDomainBlocks() {
  108. return (dispatch, getState) => {
  109. const url = getState().getIn(['domain_lists', 'blocks', 'next']);
  110. if (url === null) {
  111. return;
  112. }
  113. dispatch(expandDomainBlocksRequest());
  114. api(getState).get(url).then(response => {
  115. const next = getLinks(response).refs.find(link => link.rel === 'next');
  116. dispatch(expandDomainBlocksSuccess(response.data, next ? next.uri : null));
  117. }).catch(err => {
  118. dispatch(expandDomainBlocksFail(err));
  119. });
  120. };
  121. };
  122. export function expandDomainBlocksRequest() {
  123. return {
  124. type: DOMAIN_BLOCKS_EXPAND_REQUEST,
  125. };
  126. };
  127. export function expandDomainBlocksSuccess(domains, next) {
  128. return {
  129. type: DOMAIN_BLOCKS_EXPAND_SUCCESS,
  130. domains,
  131. next,
  132. };
  133. };
  134. export function expandDomainBlocksFail(error) {
  135. return {
  136. type: DOMAIN_BLOCKS_EXPAND_FAIL,
  137. error,
  138. };
  139. };