logo

mastofe

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

blocks.js (2272B)


  1. import api, { getLinks } from '../api';
  2. import { fetchRelationships } from './accounts';
  3. import { importFetchedAccounts } from './importer';
  4. export const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST';
  5. export const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS';
  6. export const BLOCKS_FETCH_FAIL = 'BLOCKS_FETCH_FAIL';
  7. export const BLOCKS_EXPAND_REQUEST = 'BLOCKS_EXPAND_REQUEST';
  8. export const BLOCKS_EXPAND_SUCCESS = 'BLOCKS_EXPAND_SUCCESS';
  9. export const BLOCKS_EXPAND_FAIL = 'BLOCKS_EXPAND_FAIL';
  10. export function fetchBlocks() {
  11. return (dispatch, getState) => {
  12. dispatch(fetchBlocksRequest());
  13. api(getState).get('/api/v1/blocks').then(response => {
  14. const next = getLinks(response).refs.find(link => link.rel === 'next');
  15. dispatch(importFetchedAccounts(response.data));
  16. dispatch(fetchBlocksSuccess(response.data, next ? next.uri : null));
  17. dispatch(fetchRelationships(response.data.map(item => item.id)));
  18. }).catch(error => dispatch(fetchBlocksFail(error)));
  19. };
  20. };
  21. export function fetchBlocksRequest() {
  22. return {
  23. type: BLOCKS_FETCH_REQUEST,
  24. };
  25. };
  26. export function fetchBlocksSuccess(accounts, next) {
  27. return {
  28. type: BLOCKS_FETCH_SUCCESS,
  29. accounts,
  30. next,
  31. };
  32. };
  33. export function fetchBlocksFail(error) {
  34. return {
  35. type: BLOCKS_FETCH_FAIL,
  36. error,
  37. };
  38. };
  39. export function expandBlocks() {
  40. return (dispatch, getState) => {
  41. const url = getState().getIn(['user_lists', 'blocks', 'next']);
  42. if (url === null) {
  43. return;
  44. }
  45. dispatch(expandBlocksRequest());
  46. api(getState).get(url).then(response => {
  47. const next = getLinks(response).refs.find(link => link.rel === 'next');
  48. dispatch(importFetchedAccounts(response.data));
  49. dispatch(expandBlocksSuccess(response.data, next ? next.uri : null));
  50. dispatch(fetchRelationships(response.data.map(item => item.id)));
  51. }).catch(error => dispatch(expandBlocksFail(error)));
  52. };
  53. };
  54. export function expandBlocksRequest() {
  55. return {
  56. type: BLOCKS_EXPAND_REQUEST,
  57. };
  58. };
  59. export function expandBlocksSuccess(accounts, next) {
  60. return {
  61. type: BLOCKS_EXPAND_SUCCESS,
  62. accounts,
  63. next,
  64. };
  65. };
  66. export function expandBlocksFail(error) {
  67. return {
  68. type: BLOCKS_EXPAND_FAIL,
  69. error,
  70. };
  71. };