2022-06-15 13:11:36 -07:00
|
|
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
|
|
|
|
2024-08-04 07:09:52 -07:00
|
|
|
import { getClient } from '../api';
|
2022-06-15 13:11:36 -07:00
|
|
|
|
|
|
|
import { importFetchedStatuses } from './importer';
|
|
|
|
|
|
|
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
|
|
|
import type { APIEntity } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST';
|
|
|
|
const PINNED_STATUSES_FETCH_SUCCESS = 'PINNED_STATUSES_FETCH_SUCCESS';
|
|
|
|
const PINNED_STATUSES_FETCH_FAIL = 'PINNED_STATUSES_FETCH_FAIL';
|
|
|
|
|
|
|
|
const fetchPinnedStatuses = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
if (!isLoggedIn(getState)) return;
|
|
|
|
const me = getState().me;
|
|
|
|
|
|
|
|
dispatch(fetchPinnedStatusesRequest());
|
|
|
|
|
2024-08-04 07:09:52 -07:00
|
|
|
return getClient(getState()).accounts.getAccountStatuses(me as string, { pinned: true }).then(response => {
|
|
|
|
dispatch(importFetchedStatuses(response.items));
|
|
|
|
dispatch(fetchPinnedStatusesSuccess(response.items, null));
|
2022-06-15 13:11:36 -07:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch(fetchPinnedStatusesFail(error));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchPinnedStatusesRequest = () => ({
|
|
|
|
type: PINNED_STATUSES_FETCH_REQUEST,
|
|
|
|
});
|
|
|
|
|
|
|
|
const fetchPinnedStatusesSuccess = (statuses: APIEntity[], next: string | null) => ({
|
|
|
|
type: PINNED_STATUSES_FETCH_SUCCESS,
|
|
|
|
statuses,
|
|
|
|
next,
|
|
|
|
});
|
|
|
|
|
2023-10-23 15:22:10 -07:00
|
|
|
const fetchPinnedStatusesFail = (error: unknown) => ({
|
2022-06-15 13:11:36 -07:00
|
|
|
type: PINNED_STATUSES_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
|
|
|
|
export {
|
|
|
|
PINNED_STATUSES_FETCH_REQUEST,
|
|
|
|
PINNED_STATUSES_FETCH_SUCCESS,
|
|
|
|
PINNED_STATUSES_FETCH_FAIL,
|
|
|
|
fetchPinnedStatuses,
|
|
|
|
fetchPinnedStatusesRequest,
|
|
|
|
fetchPinnedStatusesSuccess,
|
|
|
|
fetchPinnedStatusesFail,
|
|
|
|
};
|