accounts.js 1.0 KB

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