|
|
|
@ -3,7 +3,7 @@ import { defineMessages } from 'react-intl';
|
|
|
|
|
import toast from 'soapbox/toast';
|
|
|
|
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
|
|
|
|
|
|
|
|
|
import api from '../api';
|
|
|
|
|
import api, { getLinks } from '../api';
|
|
|
|
|
|
|
|
|
|
import { fetchRelationships } from './accounts';
|
|
|
|
|
import { importFetchedAccounts, importFetchedStatus } from './importer';
|
|
|
|
@ -73,6 +73,9 @@ const REMOTE_INTERACTION_REQUEST = 'REMOTE_INTERACTION_REQUEST';
|
|
|
|
|
const REMOTE_INTERACTION_SUCCESS = 'REMOTE_INTERACTION_SUCCESS';
|
|
|
|
|
const REMOTE_INTERACTION_FAIL = 'REMOTE_INTERACTION_FAIL';
|
|
|
|
|
|
|
|
|
|
const FAVOURITES_EXPAND_SUCCESS = 'FAVOURITES_EXPAND_SUCCESS';
|
|
|
|
|
const FAVOURITES_EXPAND_FAIL = 'FAVOURITES_EXPAND_FAIL';
|
|
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
|
bookmarkAdded: { id: 'status.bookmarked', defaultMessage: 'Bookmark added.' },
|
|
|
|
|
bookmarkRemoved: { id: 'status.unbookmarked', defaultMessage: 'Bookmark removed.' },
|
|
|
|
@ -412,9 +415,10 @@ const fetchFavourites = (id: string) =>
|
|
|
|
|
dispatch(fetchFavouritesRequest(id));
|
|
|
|
|
|
|
|
|
|
api(getState).get(`/api/v1/statuses/${id}/favourited_by`).then(response => {
|
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
|
dispatch(importFetchedAccounts(response.data));
|
|
|
|
|
dispatch(fetchRelationships(response.data.map((item: APIEntity) => item.id)));
|
|
|
|
|
dispatch(fetchFavouritesSuccess(id, response.data));
|
|
|
|
|
dispatch(fetchFavouritesSuccess(id, response.data, next ? next.uri : null));
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch(fetchFavouritesFail(id, error));
|
|
|
|
|
});
|
|
|
|
@ -425,10 +429,11 @@ const fetchFavouritesRequest = (id: string) => ({
|
|
|
|
|
id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const fetchFavouritesSuccess = (id: string, accounts: APIEntity[]) => ({
|
|
|
|
|
const fetchFavouritesSuccess = (id: string, accounts: APIEntity[], next: string | null) => ({
|
|
|
|
|
type: FAVOURITES_FETCH_SUCCESS,
|
|
|
|
|
id,
|
|
|
|
|
accounts,
|
|
|
|
|
next,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const fetchFavouritesFail = (id: string, error: AxiosError) => ({
|
|
|
|
@ -437,6 +442,31 @@ const fetchFavouritesFail = (id: string, error: AxiosError) => ({
|
|
|
|
|
error,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const expandFavourites = (id: string, path: string) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
api(getState).get(path).then(response => {
|
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
|
dispatch(importFetchedAccounts(response.data));
|
|
|
|
|
dispatch(fetchRelationships(response.data.map((item: APIEntity) => item.id)));
|
|
|
|
|
dispatch(expandFavouritesSuccess(id, response.data, next ? next.uri : null));
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch(expandFavouritesFail(id, error));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const expandFavouritesSuccess = (id: string, accounts: APIEntity[], next: string | null) => ({
|
|
|
|
|
type: FAVOURITES_EXPAND_SUCCESS,
|
|
|
|
|
id,
|
|
|
|
|
accounts,
|
|
|
|
|
next,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const expandFavouritesFail = (id: string, error: AxiosError) => ({
|
|
|
|
|
type: FAVOURITES_EXPAND_FAIL,
|
|
|
|
|
id,
|
|
|
|
|
error,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const fetchDislikes = (id: string) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
if (!isLoggedIn(getState)) return;
|
|
|
|
@ -669,6 +699,8 @@ export {
|
|
|
|
|
REMOTE_INTERACTION_REQUEST,
|
|
|
|
|
REMOTE_INTERACTION_SUCCESS,
|
|
|
|
|
REMOTE_INTERACTION_FAIL,
|
|
|
|
|
FAVOURITES_EXPAND_SUCCESS,
|
|
|
|
|
FAVOURITES_EXPAND_FAIL,
|
|
|
|
|
reblog,
|
|
|
|
|
unreblog,
|
|
|
|
|
toggleReblog,
|
|
|
|
@ -713,6 +745,7 @@ export {
|
|
|
|
|
fetchFavouritesRequest,
|
|
|
|
|
fetchFavouritesSuccess,
|
|
|
|
|
fetchFavouritesFail,
|
|
|
|
|
expandFavourites,
|
|
|
|
|
fetchDislikes,
|
|
|
|
|
fetchDislikesRequest,
|
|
|
|
|
fetchDislikesSuccess,
|
|
|
|
|