2022-10-11 04:32:31 -04:00
|
|
|
import api, { getLinks } from '../api';
|
2017-05-19 15:05:32 -04:00
|
|
|
|
|
|
|
export const DOMAIN_BLOCK_REQUEST = 'DOMAIN_BLOCK_REQUEST';
|
|
|
|
export const DOMAIN_BLOCK_SUCCESS = 'DOMAIN_BLOCK_SUCCESS';
|
|
|
|
export const DOMAIN_BLOCK_FAIL = 'DOMAIN_BLOCK_FAIL';
|
|
|
|
|
|
|
|
export const DOMAIN_UNBLOCK_REQUEST = 'DOMAIN_UNBLOCK_REQUEST';
|
|
|
|
export const DOMAIN_UNBLOCK_SUCCESS = 'DOMAIN_UNBLOCK_SUCCESS';
|
|
|
|
export const DOMAIN_UNBLOCK_FAIL = 'DOMAIN_UNBLOCK_FAIL';
|
|
|
|
|
|
|
|
export const DOMAIN_BLOCKS_FETCH_REQUEST = 'DOMAIN_BLOCKS_FETCH_REQUEST';
|
|
|
|
export const DOMAIN_BLOCKS_FETCH_SUCCESS = 'DOMAIN_BLOCKS_FETCH_SUCCESS';
|
|
|
|
export const DOMAIN_BLOCKS_FETCH_FAIL = 'DOMAIN_BLOCKS_FETCH_FAIL';
|
|
|
|
|
2018-03-04 15:33:08 -05:00
|
|
|
export const DOMAIN_BLOCKS_EXPAND_REQUEST = 'DOMAIN_BLOCKS_EXPAND_REQUEST';
|
|
|
|
export const DOMAIN_BLOCKS_EXPAND_SUCCESS = 'DOMAIN_BLOCKS_EXPAND_SUCCESS';
|
|
|
|
export const DOMAIN_BLOCKS_EXPAND_FAIL = 'DOMAIN_BLOCKS_EXPAND_FAIL';
|
|
|
|
|
2018-03-04 17:38:00 -05:00
|
|
|
export function blockDomain(domain) {
|
2017-05-19 15:05:32 -04:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(blockDomainRequest(domain));
|
|
|
|
|
2017-06-23 10:05:04 -04:00
|
|
|
api(getState).post('/api/v1/domain_blocks', { domain }).then(() => {
|
2018-03-04 17:38:00 -05:00
|
|
|
const at_domain = '@' + domain;
|
|
|
|
const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
|
2019-07-24 22:17:35 -04:00
|
|
|
|
2018-03-04 17:38:00 -05:00
|
|
|
dispatch(blockDomainSuccess(domain, accounts));
|
2017-05-19 15:05:32 -04:00
|
|
|
}).catch(err => {
|
|
|
|
dispatch(blockDomainFail(domain, err));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function blockDomainRequest(domain) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCK_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
domain,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-03-04 17:38:00 -05:00
|
|
|
export function blockDomainSuccess(domain, accounts) {
|
2017-05-19 15:05:32 -04:00
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCK_SUCCESS,
|
|
|
|
domain,
|
2018-03-04 17:38:00 -05:00
|
|
|
accounts,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function blockDomainFail(domain, error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCK_FAIL,
|
|
|
|
domain,
|
2017-05-20 11:31:47 -04:00
|
|
|
error,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-03-04 17:38:00 -05:00
|
|
|
export function unblockDomain(domain) {
|
2017-05-19 15:05:32 -04:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(unblockDomainRequest(domain));
|
|
|
|
|
2017-06-23 10:05:04 -04:00
|
|
|
api(getState).delete('/api/v1/domain_blocks', { params: { domain } }).then(() => {
|
2018-03-04 17:38:00 -05:00
|
|
|
const at_domain = '@' + domain;
|
|
|
|
const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
|
|
|
|
dispatch(unblockDomainSuccess(domain, accounts));
|
2017-05-19 15:05:32 -04:00
|
|
|
}).catch(err => {
|
|
|
|
dispatch(unblockDomainFail(domain, err));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function unblockDomainRequest(domain) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_UNBLOCK_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
domain,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-03-04 17:38:00 -05:00
|
|
|
export function unblockDomainSuccess(domain, accounts) {
|
2017-05-19 15:05:32 -04:00
|
|
|
return {
|
|
|
|
type: DOMAIN_UNBLOCK_SUCCESS,
|
|
|
|
domain,
|
2018-03-04 17:38:00 -05:00
|
|
|
accounts,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function unblockDomainFail(domain, error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_UNBLOCK_FAIL,
|
|
|
|
domain,
|
2017-05-20 11:31:47 -04:00
|
|
|
error,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function fetchDomainBlocks() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(fetchDomainBlocksRequest());
|
|
|
|
|
2018-03-04 16:19:20 -05:00
|
|
|
api(getState).get('/api/v1/domain_blocks').then(response => {
|
2017-05-19 15:05:32 -04:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
dispatch(fetchDomainBlocksSuccess(response.data, next ? next.uri : null));
|
|
|
|
}).catch(err => {
|
|
|
|
dispatch(fetchDomainBlocksFail(err));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function fetchDomainBlocksRequest() {
|
|
|
|
return {
|
2017-05-20 11:31:47 -04:00
|
|
|
type: DOMAIN_BLOCKS_FETCH_REQUEST,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function fetchDomainBlocksSuccess(domains, next) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_FETCH_SUCCESS,
|
|
|
|
domains,
|
2017-05-20 11:31:47 -04:00
|
|
|
next,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function fetchDomainBlocksFail(error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_FETCH_FAIL,
|
2017-05-20 11:31:47 -04:00
|
|
|
error,
|
2017-05-19 15:05:32 -04:00
|
|
|
};
|
|
|
|
};
|
2018-03-04 15:33:08 -05:00
|
|
|
|
|
|
|
export function expandDomainBlocks() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const url = getState().getIn(['domain_lists', 'blocks', 'next']);
|
|
|
|
|
2018-07-16 11:56:19 -04:00
|
|
|
if (!url) {
|
2018-03-04 15:33:08 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(expandDomainBlocksRequest());
|
|
|
|
|
|
|
|
api(getState).get(url).then(response => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
dispatch(expandDomainBlocksSuccess(response.data, next ? next.uri : null));
|
|
|
|
}).catch(err => {
|
|
|
|
dispatch(expandDomainBlocksFail(err));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function expandDomainBlocksRequest() {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_EXPAND_REQUEST,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function expandDomainBlocksSuccess(domains, next) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_EXPAND_SUCCESS,
|
|
|
|
domains,
|
|
|
|
next,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function expandDomainBlocksFail(error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_EXPAND_FAIL,
|
|
|
|
error,
|
|
|
|
};
|
|
|
|
};
|