2021-06-26 15:04:27 -07:00
|
|
|
import { defineMessages } from 'react-intl';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-12-20 07:47:46 -08:00
|
|
|
import toast from 'soapbox/toast';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2024-08-04 07:09:52 -07:00
|
|
|
import { getClient } from '../api';
|
2020-09-14 20:07:33 -07:00
|
|
|
|
2022-05-19 06:22:15 -07:00
|
|
|
import type { RootState } from 'soapbox/store';
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST';
|
|
|
|
const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS';
|
2024-07-01 11:30:37 -07:00
|
|
|
const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL';
|
2020-09-14 20:07:33 -07:00
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const IMPORT_BLOCKS_REQUEST = 'IMPORT_BLOCKS_REQUEST';
|
|
|
|
const IMPORT_BLOCKS_SUCCESS = 'IMPORT_BLOCKS_SUCCESS';
|
2024-07-01 11:30:37 -07:00
|
|
|
const IMPORT_BLOCKS_FAIL = 'IMPORT_BLOCKS_FAIL';
|
2020-09-27 10:24:38 -07:00
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const IMPORT_MUTES_REQUEST = 'IMPORT_MUTES_REQUEST';
|
|
|
|
const IMPORT_MUTES_SUCCESS = 'IMPORT_MUTES_SUCCESS';
|
2024-07-01 11:30:37 -07:00
|
|
|
const IMPORT_MUTES_FAIL = 'IMPORT_MUTES_FAIL';
|
2020-09-27 10:24:38 -07:00
|
|
|
|
2022-05-19 06:22:15 -07:00
|
|
|
type ImportDataActions = {
|
|
|
|
type: typeof IMPORT_FOLLOWS_REQUEST
|
|
|
|
| typeof IMPORT_FOLLOWS_SUCCESS
|
|
|
|
| typeof IMPORT_FOLLOWS_FAIL
|
|
|
|
| typeof IMPORT_BLOCKS_REQUEST
|
|
|
|
| typeof IMPORT_BLOCKS_SUCCESS
|
|
|
|
| typeof IMPORT_BLOCKS_FAIL
|
|
|
|
| typeof IMPORT_MUTES_REQUEST
|
|
|
|
| typeof IMPORT_MUTES_SUCCESS
|
2023-10-02 11:54:02 -07:00
|
|
|
| typeof IMPORT_MUTES_FAIL;
|
|
|
|
error?: any;
|
|
|
|
config?: string;
|
2022-12-20 09:45:46 -08:00
|
|
|
}
|
2022-05-19 06:22:15 -07:00
|
|
|
|
2021-06-26 15:04:27 -07:00
|
|
|
const messages = defineMessages({
|
|
|
|
blocksSuccess: { id: 'import_data.success.blocks', defaultMessage: 'Blocks imported successfully' },
|
|
|
|
followersSuccess: { id: 'import_data.success.followers', defaultMessage: 'Followers imported successfully' },
|
|
|
|
mutesSuccess: { id: 'import_data.success.mutes', defaultMessage: 'Mutes imported successfully' },
|
|
|
|
});
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const importFollows = (params: FormData) =>
|
2022-05-19 06:22:15 -07:00
|
|
|
(dispatch: React.Dispatch<ImportDataActions>, getState: () => RootState) => {
|
2020-09-14 20:07:33 -07:00
|
|
|
dispatch({ type: IMPORT_FOLLOWS_REQUEST });
|
2024-08-04 07:09:52 -07:00
|
|
|
return getClient(getState).request('/api/pleroma/follow_import', {
|
|
|
|
method: 'POST', body: params,
|
2024-05-11 14:37:37 -07:00
|
|
|
}).then(response => {
|
|
|
|
toast.success(messages.followersSuccess);
|
|
|
|
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.json });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: IMPORT_FOLLOWS_FAIL, error });
|
|
|
|
});
|
2020-09-14 20:07:33 -07:00
|
|
|
};
|
2020-09-27 10:24:38 -07:00
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const importBlocks = (params: FormData) =>
|
2022-05-19 06:22:15 -07:00
|
|
|
(dispatch: React.Dispatch<ImportDataActions>, getState: () => RootState) => {
|
2020-09-27 10:24:38 -07:00
|
|
|
dispatch({ type: IMPORT_BLOCKS_REQUEST });
|
2024-08-04 07:09:52 -07:00
|
|
|
return getClient(getState).request('/api/pleroma/blocks_import', {
|
|
|
|
method: 'POST', body: params,
|
2024-05-11 14:37:37 -07:00
|
|
|
}).then(response => {
|
|
|
|
toast.success(messages.blocksSuccess);
|
|
|
|
dispatch({ type: IMPORT_BLOCKS_SUCCESS, config: response.json });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: IMPORT_BLOCKS_FAIL, error });
|
|
|
|
});
|
2020-09-27 10:24:38 -07:00
|
|
|
};
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const importMutes = (params: FormData) =>
|
2022-05-19 06:22:15 -07:00
|
|
|
(dispatch: React.Dispatch<ImportDataActions>, getState: () => RootState) => {
|
2020-09-27 10:24:38 -07:00
|
|
|
dispatch({ type: IMPORT_MUTES_REQUEST });
|
2024-08-04 07:09:52 -07:00
|
|
|
return getClient(getState).request('/api/pleroma/mutes_import', {
|
|
|
|
method: 'POST', body: params,
|
2024-05-11 14:37:37 -07:00
|
|
|
}).then(response => {
|
|
|
|
toast.success(messages.mutesSuccess);
|
|
|
|
dispatch({ type: IMPORT_MUTES_SUCCESS, config: response.json });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: IMPORT_MUTES_FAIL, error });
|
|
|
|
});
|
2020-09-27 10:24:38 -07:00
|
|
|
};
|
2024-05-12 16:18:04 -07:00
|
|
|
|
|
|
|
export {
|
|
|
|
IMPORT_FOLLOWS_REQUEST,
|
|
|
|
IMPORT_FOLLOWS_SUCCESS,
|
|
|
|
IMPORT_FOLLOWS_FAIL,
|
|
|
|
IMPORT_BLOCKS_REQUEST,
|
|
|
|
IMPORT_BLOCKS_SUCCESS,
|
|
|
|
IMPORT_BLOCKS_FAIL,
|
|
|
|
IMPORT_MUTES_REQUEST,
|
|
|
|
IMPORT_MUTES_SUCCESS,
|
|
|
|
IMPORT_MUTES_FAIL,
|
|
|
|
importFollows,
|
|
|
|
importBlocks,
|
|
|
|
importMutes,
|
|
|
|
};
|