2017-05-21 01:31:47 +10:00
|
|
|
import api, { getLinks } from '../api';
|
2017-05-20 05:05:32 +10:00
|
|
|
|
2023-11-04 02:00:03 +11:00
|
|
|
import { blockDomainSuccess, unblockDomainSuccess } from "./domain_blocks_typed";
|
2024-03-16 04:36:41 +11:00
|
|
|
import { openModal } from './modal';
|
|
|
|
|
2023-11-04 02:00:03 +11:00
|
|
|
|
|
|
|
export * from "./domain_blocks_typed";
|
|
|
|
|
2017-05-20 05:05:32 +10:00
|
|
|
export const DOMAIN_BLOCK_REQUEST = 'DOMAIN_BLOCK_REQUEST';
|
|
|
|
export const DOMAIN_BLOCK_FAIL = 'DOMAIN_BLOCK_FAIL';
|
|
|
|
|
|
|
|
export const DOMAIN_UNBLOCK_REQUEST = 'DOMAIN_UNBLOCK_REQUEST';
|
|
|
|
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-30 21:38:00 +11: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';
|
|
|
|
|
|
|
|
export function blockDomain(domain) {
|
2017-05-20 05:05:32 +10:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(blockDomainRequest(domain));
|
|
|
|
|
2024-05-23 00:45:18 +10:00
|
|
|
api().post('/api/v1/domain_blocks', { domain }).then(() => {
|
2018-03-30 21:38:00 +11: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-25 12:17:35 +10:00
|
|
|
|
2023-11-04 02:00:03 +11:00
|
|
|
dispatch(blockDomainSuccess({ domain, accounts }));
|
2017-05-20 05:05:32 +10:00
|
|
|
}).catch(err => {
|
|
|
|
dispatch(blockDomainFail(domain, err));
|
|
|
|
});
|
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function blockDomainRequest(domain) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCK_REQUEST,
|
2017-05-21 01:31:47 +10:00
|
|
|
domain,
|
2017-05-20 05:05:32 +10:00
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function blockDomainFail(domain, error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCK_FAIL,
|
|
|
|
domain,
|
2017-05-21 01:31:47 +10:00
|
|
|
error,
|
2017-05-20 05:05:32 +10:00
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
2018-03-30 21:38:00 +11:00
|
|
|
export function unblockDomain(domain) {
|
2017-05-20 05:05:32 +10:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(unblockDomainRequest(domain));
|
|
|
|
|
2024-05-23 00:45:18 +10:00
|
|
|
api().delete('/api/v1/domain_blocks', { params: { domain } }).then(() => {
|
2018-03-30 21:38:00 +11:00
|
|
|
const at_domain = '@' + domain;
|
|
|
|
const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
|
2023-11-04 02:00:03 +11:00
|
|
|
dispatch(unblockDomainSuccess({ domain, accounts }));
|
2017-05-20 05:05:32 +10:00
|
|
|
}).catch(err => {
|
|
|
|
dispatch(unblockDomainFail(domain, err));
|
|
|
|
});
|
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function unblockDomainRequest(domain) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_UNBLOCK_REQUEST,
|
2017-05-21 01:31:47 +10:00
|
|
|
domain,
|
2017-05-20 05:05:32 +10:00
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function unblockDomainFail(domain, error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_UNBLOCK_FAIL,
|
|
|
|
domain,
|
2017-05-21 01:31:47 +10:00
|
|
|
error,
|
2017-05-20 05:05:32 +10:00
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function fetchDomainBlocks() {
|
2024-05-23 00:45:18 +10:00
|
|
|
return (dispatch) => {
|
2017-05-20 05:05:32 +10:00
|
|
|
dispatch(fetchDomainBlocksRequest());
|
|
|
|
|
2024-05-23 00:45:18 +10:00
|
|
|
api().get('/api/v1/domain_blocks').then(response => {
|
2017-05-20 05:05:32 +10:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
dispatch(fetchDomainBlocksSuccess(response.data, next ? next.uri : null));
|
|
|
|
}).catch(err => {
|
|
|
|
dispatch(fetchDomainBlocksFail(err));
|
|
|
|
});
|
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function fetchDomainBlocksRequest() {
|
|
|
|
return {
|
2017-05-21 01:31:47 +10:00
|
|
|
type: DOMAIN_BLOCKS_FETCH_REQUEST,
|
2017-05-20 05:05:32 +10:00
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function fetchDomainBlocksSuccess(domains, next) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_FETCH_SUCCESS,
|
|
|
|
domains,
|
2017-05-21 01:31:47 +10:00
|
|
|
next,
|
2017-05-20 05:05:32 +10:00
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2017-05-20 05:05:32 +10:00
|
|
|
|
|
|
|
export function fetchDomainBlocksFail(error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_FETCH_FAIL,
|
2017-05-21 01:31:47 +10:00
|
|
|
error,
|
2017-05-20 05:05:32 +10:00
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2018-03-30 21:38:00 +11:00
|
|
|
|
|
|
|
export function expandDomainBlocks() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const url = getState().getIn(['domain_lists', 'blocks', 'next']);
|
|
|
|
|
2018-07-15 07:28:29 +10:00
|
|
|
if (!url) {
|
2018-03-30 21:38:00 +11:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(expandDomainBlocksRequest());
|
|
|
|
|
2024-05-23 00:45:18 +10:00
|
|
|
api().get(url).then(response => {
|
2018-03-30 21:38:00 +11:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
dispatch(expandDomainBlocksSuccess(response.data, next ? next.uri : null));
|
|
|
|
}).catch(err => {
|
|
|
|
dispatch(expandDomainBlocksFail(err));
|
|
|
|
});
|
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2018-03-30 21:38:00 +11:00
|
|
|
|
|
|
|
export function expandDomainBlocksRequest() {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_EXPAND_REQUEST,
|
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2018-03-30 21:38:00 +11:00
|
|
|
|
|
|
|
export function expandDomainBlocksSuccess(domains, next) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_EXPAND_SUCCESS,
|
|
|
|
domains,
|
|
|
|
next,
|
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2018-03-30 21:38:00 +11:00
|
|
|
|
|
|
|
export function expandDomainBlocksFail(error) {
|
|
|
|
return {
|
|
|
|
type: DOMAIN_BLOCKS_EXPAND_FAIL,
|
|
|
|
error,
|
|
|
|
};
|
2022-12-19 02:51:37 +11:00
|
|
|
}
|
2024-03-16 04:36:41 +11:00
|
|
|
|
|
|
|
export const initDomainBlockModal = account => dispatch => dispatch(openModal({
|
|
|
|
modalType: 'DOMAIN_BLOCK',
|
|
|
|
modalProps: {
|
|
|
|
domain: account.get('acct').split('@')[1],
|
|
|
|
acct: account.get('acct'),
|
|
|
|
accountId: account.get('id'),
|
|
|
|
},
|
|
|
|
}));
|