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

33 lines
830 B

  1. import { ACCOUNT_IMPORT, ACCOUNTS_IMPORT } from '../actions/importer';
  2. import { Map as ImmutableMap, fromJS } from 'immutable';
  3. const initialState = ImmutableMap();
  4. const normalizeAccount = (state, account) => {
  5. account = { ...account };
  6. delete account.followers_count;
  7. delete account.following_count;
  8. delete account.statuses_count;
  9. return state.set(account.id, fromJS(account));
  10. };
  11. const normalizeAccounts = (state, accounts) => {
  12. accounts.forEach(account => {
  13. state = normalizeAccount(state, account);
  14. });
  15. return state;
  16. };
  17. export default function accounts(state = initialState, action) {
  18. switch(action.type) {
  19. case ACCOUNT_IMPORT:
  20. return normalizeAccount(state, action.account);
  21. case ACCOUNTS_IMPORT:
  22. return normalizeAccounts(state, action.accounts);
  23. default:
  24. return state;
  25. }
  26. };