The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

59 lines
1.6 KiB

  1. import {
  2. ACCOUNT_FOLLOW_SUCCESS,
  3. ACCOUNT_UNFOLLOW_SUCCESS,
  4. ACCOUNT_BLOCK_SUCCESS,
  5. ACCOUNT_UNBLOCK_SUCCESS,
  6. ACCOUNT_MUTE_SUCCESS,
  7. ACCOUNT_UNMUTE_SUCCESS,
  8. ACCOUNT_PIN_SUCCESS,
  9. ACCOUNT_UNPIN_SUCCESS,
  10. RELATIONSHIPS_FETCH_SUCCESS,
  11. } from '../actions/accounts';
  12. import {
  13. DOMAIN_BLOCK_SUCCESS,
  14. DOMAIN_UNBLOCK_SUCCESS,
  15. } from '../actions/domain_blocks';
  16. import { Map as ImmutableMap, fromJS } from 'immutable';
  17. const normalizeRelationship = (state, relationship) => state.set(relationship.id, fromJS(relationship));
  18. const normalizeRelationships = (state, relationships) => {
  19. relationships.forEach(relationship => {
  20. state = normalizeRelationship(state, relationship);
  21. });
  22. return state;
  23. };
  24. const setDomainBlocking = (state, accounts, blocking) => {
  25. return state.withMutations(map => {
  26. accounts.forEach(id => {
  27. map.setIn([id, 'domain_blocking'], blocking);
  28. });
  29. });
  30. };
  31. const initialState = ImmutableMap();
  32. export default function relationships(state = initialState, action) {
  33. switch(action.type) {
  34. case ACCOUNT_FOLLOW_SUCCESS:
  35. case ACCOUNT_UNFOLLOW_SUCCESS:
  36. case ACCOUNT_BLOCK_SUCCESS:
  37. case ACCOUNT_UNBLOCK_SUCCESS:
  38. case ACCOUNT_MUTE_SUCCESS:
  39. case ACCOUNT_UNMUTE_SUCCESS:
  40. case ACCOUNT_PIN_SUCCESS:
  41. case ACCOUNT_UNPIN_SUCCESS:
  42. return normalizeRelationship(state, action.relationship);
  43. case RELATIONSHIPS_FETCH_SUCCESS:
  44. return normalizeRelationships(state, action.relationships);
  45. case DOMAIN_BLOCK_SUCCESS:
  46. return setDomainBlocking(state, action.accounts, true);
  47. case DOMAIN_UNBLOCK_SUCCESS:
  48. return setDomainBlocking(state, action.accounts, false);
  49. default:
  50. return state;
  51. }
  52. };