logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

accounts.js (830B)


  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. };