logo

mastofe

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

user_lists.js (2973B)


  1. import {
  2. FOLLOWERS_FETCH_SUCCESS,
  3. FOLLOWERS_EXPAND_SUCCESS,
  4. FOLLOWING_FETCH_SUCCESS,
  5. FOLLOWING_EXPAND_SUCCESS,
  6. FOLLOW_REQUESTS_FETCH_SUCCESS,
  7. FOLLOW_REQUESTS_EXPAND_SUCCESS,
  8. FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
  9. FOLLOW_REQUEST_REJECT_SUCCESS,
  10. } from '../actions/accounts';
  11. import {
  12. REBLOGS_FETCH_SUCCESS,
  13. FAVOURITES_FETCH_SUCCESS,
  14. } from '../actions/interactions';
  15. import {
  16. BLOCKS_FETCH_SUCCESS,
  17. BLOCKS_EXPAND_SUCCESS,
  18. } from '../actions/blocks';
  19. import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
  20. const initialState = ImmutableMap({
  21. followers: ImmutableMap(),
  22. following: ImmutableMap(),
  23. reblogged_by: ImmutableMap(),
  24. favourited_by: ImmutableMap(),
  25. follow_requests: ImmutableMap(),
  26. blocks: ImmutableMap(),
  27. });
  28. const normalizeList = (state, type, id, accounts, next) => {
  29. return state.setIn([type, id], ImmutableMap({
  30. next,
  31. items: ImmutableList(accounts.map(item => item.id)),
  32. }));
  33. };
  34. const appendToList = (state, type, id, accounts, next) => {
  35. return state.updateIn([type, id], map => {
  36. return map.set('next', next).update('items', list => list.concat(accounts.map(item => item.id)));
  37. });
  38. };
  39. export default function userLists(state = initialState, action) {
  40. switch(action.type) {
  41. case FOLLOWERS_FETCH_SUCCESS:
  42. return normalizeList(state, 'followers', action.id, action.accounts, action.next);
  43. case FOLLOWERS_EXPAND_SUCCESS:
  44. return appendToList(state, 'followers', action.id, action.accounts, action.next);
  45. case FOLLOWING_FETCH_SUCCESS:
  46. return normalizeList(state, 'following', action.id, action.accounts, action.next);
  47. case FOLLOWING_EXPAND_SUCCESS:
  48. return appendToList(state, 'following', action.id, action.accounts, action.next);
  49. case REBLOGS_FETCH_SUCCESS:
  50. return state.setIn(['reblogged_by', action.id], ImmutableList(action.accounts.map(item => item.id)));
  51. case FAVOURITES_FETCH_SUCCESS:
  52. return state.setIn(['favourited_by', action.id], ImmutableList(action.accounts.map(item => item.id)));
  53. case FOLLOW_REQUESTS_FETCH_SUCCESS:
  54. return state.setIn(['follow_requests', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['follow_requests', 'next'], action.next);
  55. case FOLLOW_REQUESTS_EXPAND_SUCCESS:
  56. return state.updateIn(['follow_requests', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['follow_requests', 'next'], action.next);
  57. case FOLLOW_REQUEST_AUTHORIZE_SUCCESS:
  58. case FOLLOW_REQUEST_REJECT_SUCCESS:
  59. return state.updateIn(['follow_requests', 'items'], list => list.filterNot(item => item === action.id));
  60. case BLOCKS_FETCH_SUCCESS:
  61. return state.setIn(['blocks', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['blocks', 'next'], action.next);
  62. case BLOCKS_EXPAND_SUCCESS:
  63. return state.updateIn(['blocks', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['blocks', 'next'], action.next);
  64. default:
  65. return state;
  66. }
  67. };