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.

34 lines
986 B

  1. import {
  2. ACCOUNT_FOLLOW_SUCCESS,
  3. ACCOUNT_UNFOLLOW_SUCCESS,
  4. ACCOUNT_BLOCK_SUCCESS,
  5. ACCOUNT_UNBLOCK_SUCCESS,
  6. RELATIONSHIPS_FETCH_SUCCESS
  7. } from '../actions/accounts';
  8. import Immutable from 'immutable';
  9. const normalizeRelationship = (state, relationship) => state.set(relationship.id, Immutable.fromJS(relationship));
  10. const normalizeRelationships = (state, relationships) => {
  11. relationships.forEach(relationship => {
  12. state = normalizeRelationship(state, relationship);
  13. });
  14. return state;
  15. };
  16. const initialState = Immutable.Map();
  17. export default function relationships(state = initialState, action) {
  18. switch(action.type) {
  19. case ACCOUNT_FOLLOW_SUCCESS:
  20. case ACCOUNT_UNFOLLOW_SUCCESS:
  21. case ACCOUNT_BLOCK_SUCCESS:
  22. case ACCOUNT_UNBLOCK_SUCCESS:
  23. return normalizeRelationship(state, action.relationship);
  24. case RELATIONSHIPS_FETCH_SUCCESS:
  25. return normalizeRelationships(state, action.relationships);
  26. default:
  27. return state;
  28. }
  29. };