闭社主体 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.

46 lines
1.4 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 {
  11. DOMAIN_BLOCK_SUCCESS,
  12. DOMAIN_UNBLOCK_SUCCESS,
  13. } from '../actions/domain_blocks';
  14. import { Map as ImmutableMap, fromJS } from 'immutable';
  15. const normalizeRelationship = (state, relationship) => state.set(relationship.id, fromJS(relationship));
  16. const normalizeRelationships = (state, relationships) => {
  17. relationships.forEach(relationship => {
  18. state = normalizeRelationship(state, relationship);
  19. });
  20. return state;
  21. };
  22. const initialState = ImmutableMap();
  23. export default function relationships(state = initialState, action) {
  24. switch(action.type) {
  25. case ACCOUNT_FOLLOW_SUCCESS:
  26. case ACCOUNT_UNFOLLOW_SUCCESS:
  27. case ACCOUNT_BLOCK_SUCCESS:
  28. case ACCOUNT_UNBLOCK_SUCCESS:
  29. case ACCOUNT_MUTE_SUCCESS:
  30. case ACCOUNT_UNMUTE_SUCCESS:
  31. return normalizeRelationship(state, action.relationship);
  32. case RELATIONSHIPS_FETCH_SUCCESS:
  33. return normalizeRelationships(state, action.relationships);
  34. case DOMAIN_BLOCK_SUCCESS:
  35. return state.setIn([action.accountId, 'domain_blocking'], true);
  36. case DOMAIN_UNBLOCK_SUCCESS:
  37. return state.setIn([action.accountId, 'domain_blocking'], false);
  38. default:
  39. return state;
  40. }
  41. };