闭社主体 forked from https://github.com/tootsuite/mastodon
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.

38 lines
1.1 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. RELATIONSHIPS_FETCH_SUCCESS
  9. } from '../actions/accounts';
  10. import Immutable from 'immutable';
  11. const normalizeRelationship = (state, relationship) => state.set(relationship.id, Immutable.fromJS(relationship));
  12. const normalizeRelationships = (state, relationships) => {
  13. relationships.forEach(relationship => {
  14. state = normalizeRelationship(state, relationship);
  15. });
  16. return state;
  17. };
  18. const initialState = Immutable.Map();
  19. export default function relationships(state = initialState, action) {
  20. switch(action.type) {
  21. case ACCOUNT_FOLLOW_SUCCESS:
  22. case ACCOUNT_UNFOLLOW_SUCCESS:
  23. case ACCOUNT_BLOCK_SUCCESS:
  24. case ACCOUNT_UNBLOCK_SUCCESS:
  25. case ACCOUNT_MUTE_SUCCESS:
  26. case ACCOUNT_UNMUTE_SUCCESS:
  27. return normalizeRelationship(state, action.relationship);
  28. case RELATIONSHIPS_FETCH_SUCCESS:
  29. return normalizeRelationships(state, action.relationships);
  30. default:
  31. return state;
  32. }
  33. };