mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-12-24 14:17:08 +00:00
155424e52f
I don't like it changing files this way, but it's basically what
c49213f0ea
and a few others did.
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import {
|
|
ACCOUNT_FOLLOW_SUCCESS,
|
|
ACCOUNT_UNFOLLOW_SUCCESS,
|
|
} from '../actions/accounts';
|
|
import { ACCOUNT_IMPORT, ACCOUNTS_IMPORT } from '../actions/importer';
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
|
|
const normalizeAccount = (state, account) => state.set(account.id, fromJS({
|
|
followers_count: account.followers_count,
|
|
following_count: account.following_count,
|
|
statuses_count: account.statuses_count,
|
|
}));
|
|
|
|
const normalizeAccounts = (state, accounts) => {
|
|
accounts.forEach(account => {
|
|
state = normalizeAccount(state, account);
|
|
});
|
|
|
|
return state;
|
|
};
|
|
|
|
const initialState = ImmutableMap();
|
|
|
|
export default function accountsCounters(state = initialState, action) {
|
|
switch(action.type) {
|
|
case ACCOUNT_IMPORT:
|
|
return normalizeAccount(state, action.account);
|
|
case ACCOUNTS_IMPORT:
|
|
return normalizeAccounts(state, action.accounts);
|
|
case ACCOUNT_FOLLOW_SUCCESS:
|
|
return action.alreadyFollowing ? state :
|
|
state.updateIn([action.relationship.id, 'followers_count'], num => num + 1);
|
|
case ACCOUNT_UNFOLLOW_SUCCESS:
|
|
return state.updateIn([action.relationship.id, 'followers_count'], num => Math.max(0, num - 1));
|
|
default:
|
|
return state;
|
|
}
|
|
}
|