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.
47 lines
1.4 KiB
47 lines
1.4 KiB
8 years ago
|
import {
|
||
|
ACCOUNT_FOLLOW_SUCCESS,
|
||
|
ACCOUNT_UNFOLLOW_SUCCESS,
|
||
|
ACCOUNT_BLOCK_SUCCESS,
|
||
|
ACCOUNT_UNBLOCK_SUCCESS,
|
||
8 years ago
|
ACCOUNT_MUTE_SUCCESS,
|
||
|
ACCOUNT_UNMUTE_SUCCESS,
|
||
8 years ago
|
RELATIONSHIPS_FETCH_SUCCESS,
|
||
7 years ago
|
} from 'flavours/glitch/actions/accounts';
|
||
8 years ago
|
import {
|
||
|
DOMAIN_BLOCK_SUCCESS,
|
||
8 years ago
|
DOMAIN_UNBLOCK_SUCCESS,
|
||
7 years ago
|
} from 'flavours/glitch/actions/domain_blocks';
|
||
7 years ago
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||
8 years ago
|
|
||
7 years ago
|
const normalizeRelationship = (state, relationship) => state.set(relationship.id, fromJS(relationship));
|
||
8 years ago
|
|
||
|
const normalizeRelationships = (state, relationships) => {
|
||
|
relationships.forEach(relationship => {
|
||
|
state = normalizeRelationship(state, relationship);
|
||
|
});
|
||
|
|
||
|
return state;
|
||
|
};
|
||
|
|
||
7 years ago
|
const initialState = ImmutableMap();
|
||
8 years ago
|
|
||
|
export default function relationships(state = initialState, action) {
|
||
|
switch(action.type) {
|
||
8 years ago
|
case ACCOUNT_FOLLOW_SUCCESS:
|
||
|
case ACCOUNT_UNFOLLOW_SUCCESS:
|
||
|
case ACCOUNT_BLOCK_SUCCESS:
|
||
|
case ACCOUNT_UNBLOCK_SUCCESS:
|
||
|
case ACCOUNT_MUTE_SUCCESS:
|
||
|
case ACCOUNT_UNMUTE_SUCCESS:
|
||
|
return normalizeRelationship(state, action.relationship);
|
||
|
case RELATIONSHIPS_FETCH_SUCCESS:
|
||
|
return normalizeRelationships(state, action.relationships);
|
||
8 years ago
|
case DOMAIN_BLOCK_SUCCESS:
|
||
|
return state.setIn([action.accountId, 'domain_blocking'], true);
|
||
|
case DOMAIN_UNBLOCK_SUCCESS:
|
||
|
return state.setIn([action.accountId, 'domain_blocking'], false);
|
||
8 years ago
|
default:
|
||
|
return state;
|
||
8 years ago
|
}
|
||
|
};
|