2024-08-04 07:09:52 -07:00
|
|
|
import { getClient, getNextLink } from '../api';
|
2022-11-29 15:32:21 -08:00
|
|
|
|
|
|
|
import { importFetchedStatuses } from './importer';
|
|
|
|
|
|
|
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const STATUS_QUOTES_FETCH_REQUEST = 'STATUS_QUOTES_FETCH_REQUEST';
|
|
|
|
const STATUS_QUOTES_FETCH_SUCCESS = 'STATUS_QUOTES_FETCH_SUCCESS';
|
|
|
|
const STATUS_QUOTES_FETCH_FAIL = 'STATUS_QUOTES_FETCH_FAIL';
|
2022-11-29 15:32:21 -08:00
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const STATUS_QUOTES_EXPAND_REQUEST = 'STATUS_QUOTES_EXPAND_REQUEST';
|
|
|
|
const STATUS_QUOTES_EXPAND_SUCCESS = 'STATUS_QUOTES_EXPAND_SUCCESS';
|
|
|
|
const STATUS_QUOTES_EXPAND_FAIL = 'STATUS_QUOTES_EXPAND_FAIL';
|
2022-11-29 15:32:21 -08:00
|
|
|
|
|
|
|
const noOp = () => new Promise(f => f(null));
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const fetchStatusQuotes = (statusId: string) =>
|
2022-11-29 15:32:21 -08:00
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
if (getState().status_lists.getIn([`quotes:${statusId}`, 'isLoading'])) {
|
|
|
|
return dispatch(noOp);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
statusId,
|
|
|
|
type: STATUS_QUOTES_FETCH_REQUEST,
|
|
|
|
});
|
|
|
|
|
2024-08-04 07:09:52 -07:00
|
|
|
return getClient(getState).request(`/api/v1/pleroma/statuses/${statusId}/quotes`).then(response => {
|
2024-06-13 14:55:37 -07:00
|
|
|
const next = getNextLink(response);
|
2024-05-11 14:37:37 -07:00
|
|
|
dispatch(importFetchedStatuses(response.json));
|
2022-11-29 15:32:21 -08:00
|
|
|
return dispatch({
|
|
|
|
type: STATUS_QUOTES_FETCH_SUCCESS,
|
|
|
|
statusId,
|
2024-05-11 14:37:37 -07:00
|
|
|
statuses: response.json,
|
2024-06-13 14:55:37 -07:00
|
|
|
next: next || null,
|
2022-11-29 15:32:21 -08:00
|
|
|
});
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: STATUS_QUOTES_FETCH_FAIL,
|
|
|
|
statusId,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const expandStatusQuotes = (statusId: string) =>
|
2022-11-29 15:32:21 -08:00
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
const url = getState().status_lists.getIn([`quotes:${statusId}`, 'next'], null) as string | null;
|
|
|
|
|
|
|
|
if (url === null || getState().status_lists.getIn([`quotes:${statusId}`, 'isLoading'])) {
|
|
|
|
return dispatch(noOp);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: STATUS_QUOTES_EXPAND_REQUEST,
|
|
|
|
statusId,
|
|
|
|
});
|
|
|
|
|
2024-08-04 07:09:52 -07:00
|
|
|
return getClient(getState).request(url).then(response => {
|
2024-06-13 14:55:37 -07:00
|
|
|
const next = getNextLink(response);
|
2024-05-11 14:37:37 -07:00
|
|
|
dispatch(importFetchedStatuses(response.json));
|
2022-11-29 15:32:21 -08:00
|
|
|
dispatch({
|
|
|
|
type: STATUS_QUOTES_EXPAND_SUCCESS,
|
|
|
|
statusId,
|
2024-05-11 14:37:37 -07:00
|
|
|
statuses: response.json,
|
2024-06-13 14:55:37 -07:00
|
|
|
next: next || null,
|
2022-11-29 15:32:21 -08:00
|
|
|
});
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: STATUS_QUOTES_EXPAND_FAIL,
|
|
|
|
statusId,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2024-05-12 16:18:04 -07:00
|
|
|
|
|
|
|
export {
|
|
|
|
STATUS_QUOTES_FETCH_REQUEST,
|
|
|
|
STATUS_QUOTES_FETCH_SUCCESS,
|
|
|
|
STATUS_QUOTES_FETCH_FAIL,
|
|
|
|
STATUS_QUOTES_EXPAND_REQUEST,
|
|
|
|
STATUS_QUOTES_EXPAND_SUCCESS,
|
|
|
|
STATUS_QUOTES_EXPAND_FAIL,
|
|
|
|
fetchStatusQuotes,
|
|
|
|
expandStatusQuotes,
|
|
|
|
};
|