|
|
@ -21,6 +21,7 @@ import {
|
|
|
|
DOMAIN_BLOCK_SUCCESS,
|
|
|
|
DOMAIN_BLOCK_SUCCESS,
|
|
|
|
DOMAIN_UNBLOCK_SUCCESS,
|
|
|
|
DOMAIN_UNBLOCK_SUCCESS,
|
|
|
|
} from '../actions/domain_blocks';
|
|
|
|
} from '../actions/domain_blocks';
|
|
|
|
|
|
|
|
import { STREAMING_FOLLOW_RELATIONSHIPS_UPDATE } from 'soapbox/actions/streaming';
|
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
|
|
import { get } from 'lodash';
|
|
|
|
import { get } from 'lodash';
|
|
|
|
|
|
|
|
|
|
|
@ -57,6 +58,24 @@ const importPleromaAccounts = (state, accounts) => {
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const followStateToRelationship = followState => {
|
|
|
|
|
|
|
|
switch(followState) {
|
|
|
|
|
|
|
|
case 'follow_pending':
|
|
|
|
|
|
|
|
return { following: false, requested: true };
|
|
|
|
|
|
|
|
case 'follow_accept':
|
|
|
|
|
|
|
|
return { following: true, requested: false };
|
|
|
|
|
|
|
|
case 'follow_reject':
|
|
|
|
|
|
|
|
return { following: false, requested: false };
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateFollowRelationship = (state, id, followState) => {
|
|
|
|
|
|
|
|
const map = followStateToRelationship(followState);
|
|
|
|
|
|
|
|
return state.update(id, ImmutableMap(), relationship => relationship.merge(map));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const initialState = ImmutableMap();
|
|
|
|
const initialState = ImmutableMap();
|
|
|
|
|
|
|
|
|
|
|
|
export default function relationships(state = initialState, action) {
|
|
|
|
export default function relationships(state = initialState, action) {
|
|
|
@ -66,9 +85,9 @@ export default function relationships(state = initialState, action) {
|
|
|
|
case ACCOUNTS_IMPORT:
|
|
|
|
case ACCOUNTS_IMPORT:
|
|
|
|
return importPleromaAccounts(state, action.accounts);
|
|
|
|
return importPleromaAccounts(state, action.accounts);
|
|
|
|
case ACCOUNT_FOLLOW_REQUEST:
|
|
|
|
case ACCOUNT_FOLLOW_REQUEST:
|
|
|
|
return state.setIn([action.id, action.locked ? 'requested' : 'following'], true);
|
|
|
|
return state.setIn([action.id, 'requested'], true);
|
|
|
|
case ACCOUNT_FOLLOW_FAIL:
|
|
|
|
case ACCOUNT_FOLLOW_FAIL:
|
|
|
|
return state.setIn([action.id, action.locked ? 'requested' : 'following'], false);
|
|
|
|
return state.setIn([action.id, 'requested'], false);
|
|
|
|
case ACCOUNT_UNFOLLOW_REQUEST:
|
|
|
|
case ACCOUNT_UNFOLLOW_REQUEST:
|
|
|
|
return state.setIn([action.id, 'following'], false);
|
|
|
|
return state.setIn([action.id, 'following'], false);
|
|
|
|
case ACCOUNT_UNFOLLOW_FAIL:
|
|
|
|
case ACCOUNT_UNFOLLOW_FAIL:
|
|
|
@ -88,6 +107,12 @@ export default function relationships(state = initialState, action) {
|
|
|
|
return setDomainBlocking(state, action.accounts, true);
|
|
|
|
return setDomainBlocking(state, action.accounts, true);
|
|
|
|
case DOMAIN_UNBLOCK_SUCCESS:
|
|
|
|
case DOMAIN_UNBLOCK_SUCCESS:
|
|
|
|
return setDomainBlocking(state, action.accounts, false);
|
|
|
|
return setDomainBlocking(state, action.accounts, false);
|
|
|
|
|
|
|
|
case STREAMING_FOLLOW_RELATIONSHIPS_UPDATE:
|
|
|
|
|
|
|
|
if (action.follower.id === action.me) {
|
|
|
|
|
|
|
|
return updateFollowRelationship(state, action.following.id, action.state);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|