2023-08-29 04:56:19 -04:00
|
|
|
import api, { getLinks } from '../api';
|
2023-05-28 10:38:10 -04:00
|
|
|
|
2023-08-29 04:56:19 -04:00
|
|
|
import { fetchRelationships } from './accounts';
|
2019-03-05 14:15:43 -05:00
|
|
|
import { importFetchedAccounts, importFetchedStatus } from './importer';
|
2016-09-01 07:21:48 -04:00
|
|
|
|
|
|
|
export const REBLOG_REQUEST = 'REBLOG_REQUEST';
|
|
|
|
export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
|
|
|
|
export const REBLOG_FAIL = 'REBLOG_FAIL';
|
|
|
|
|
2023-08-29 08:42:20 -04:00
|
|
|
export const REBLOGS_EXPAND_REQUEST = 'REBLOGS_EXPAND_REQUEST';
|
|
|
|
export const REBLOGS_EXPAND_SUCCESS = 'REBLOGS_EXPAND_SUCCESS';
|
|
|
|
export const REBLOGS_EXPAND_FAIL = 'REBLOGS_EXPAND_FAIL';
|
|
|
|
|
2016-09-01 07:21:48 -04:00
|
|
|
export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
|
|
|
|
export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
|
|
|
|
export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
|
|
|
|
|
2016-10-02 09:14:26 -04:00
|
|
|
export const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST';
|
|
|
|
export const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS';
|
|
|
|
export const UNREBLOG_FAIL = 'UNREBLOG_FAIL';
|
|
|
|
|
|
|
|
export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST';
|
|
|
|
export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS';
|
|
|
|
export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL';
|
|
|
|
|
2016-11-03 15:16:14 -04:00
|
|
|
export const REBLOGS_FETCH_REQUEST = 'REBLOGS_FETCH_REQUEST';
|
|
|
|
export const REBLOGS_FETCH_SUCCESS = 'REBLOGS_FETCH_SUCCESS';
|
|
|
|
export const REBLOGS_FETCH_FAIL = 'REBLOGS_FETCH_FAIL';
|
|
|
|
|
2016-11-04 07:48:53 -04:00
|
|
|
export const FAVOURITES_FETCH_REQUEST = 'FAVOURITES_FETCH_REQUEST';
|
|
|
|
export const FAVOURITES_FETCH_SUCCESS = 'FAVOURITES_FETCH_SUCCESS';
|
|
|
|
export const FAVOURITES_FETCH_FAIL = 'FAVOURITES_FETCH_FAIL';
|
|
|
|
|
2023-08-29 04:56:19 -04:00
|
|
|
export const FAVOURITES_EXPAND_REQUEST = 'FAVOURITES_EXPAND_REQUEST';
|
|
|
|
export const FAVOURITES_EXPAND_SUCCESS = 'FAVOURITES_EXPAND_SUCCESS';
|
|
|
|
export const FAVOURITES_EXPAND_FAIL = 'FAVOURITES_EXPAND_FAIL';
|
|
|
|
|
2017-08-24 19:41:18 -04:00
|
|
|
export const PIN_REQUEST = 'PIN_REQUEST';
|
|
|
|
export const PIN_SUCCESS = 'PIN_SUCCESS';
|
|
|
|
export const PIN_FAIL = 'PIN_FAIL';
|
|
|
|
|
|
|
|
export const UNPIN_REQUEST = 'UNPIN_REQUEST';
|
|
|
|
export const UNPIN_SUCCESS = 'UNPIN_SUCCESS';
|
|
|
|
export const UNPIN_FAIL = 'UNPIN_FAIL';
|
|
|
|
|
2018-04-11 13:42:25 -04:00
|
|
|
export const BOOKMARK_REQUEST = 'BOOKMARK_REQUEST';
|
|
|
|
export const BOOKMARK_SUCCESS = 'BOOKMARKED_SUCCESS';
|
|
|
|
export const BOOKMARK_FAIL = 'BOOKMARKED_FAIL';
|
|
|
|
|
|
|
|
export const UNBOOKMARK_REQUEST = 'UNBOOKMARKED_REQUEST';
|
|
|
|
export const UNBOOKMARK_SUCCESS = 'UNBOOKMARKED_SUCCESS';
|
|
|
|
export const UNBOOKMARK_FAIL = 'UNBOOKMARKED_FAIL';
|
|
|
|
|
2021-02-10 18:53:12 -05:00
|
|
|
export function reblog(status, visibility) {
|
2016-09-01 07:21:48 -04:00
|
|
|
return function (dispatch, getState) {
|
|
|
|
dispatch(reblogRequest(status));
|
|
|
|
|
2021-02-10 18:53:12 -05:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`, { visibility }).then(function (response) {
|
2016-09-01 08:12:11 -04:00
|
|
|
// The reblog API method returns a new status wrapped around the original. In this case we are only
|
|
|
|
// interested in how the original is modified, hence passing it skipping the wrapper
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data.reblog));
|
|
|
|
dispatch(reblogSuccess(status));
|
2016-09-01 07:21:48 -04:00
|
|
|
}).catch(function (error) {
|
|
|
|
dispatch(reblogFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-01 07:21:48 -04:00
|
|
|
|
2016-09-26 17:55:21 -04:00
|
|
|
export function unreblog(status) {
|
|
|
|
return (dispatch, getState) => {
|
2016-10-02 09:14:26 -04:00
|
|
|
dispatch(unreblogRequest(status));
|
|
|
|
|
2016-09-27 10:58:23 -04:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
dispatch(unreblogSuccess(status));
|
2016-09-26 17:55:21 -04:00
|
|
|
}).catch(error => {
|
2016-10-02 09:14:26 -04:00
|
|
|
dispatch(unreblogFail(status, error));
|
2016-09-26 17:55:21 -04:00
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-26 17:55:21 -04:00
|
|
|
|
2016-09-01 07:21:48 -04:00
|
|
|
export function reblogRequest(status) {
|
|
|
|
return {
|
|
|
|
type: REBLOG_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
status: status,
|
2016-09-01 07:21:48 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-01 07:21:48 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function reblogSuccess(status) {
|
2016-09-01 07:21:48 -04:00
|
|
|
return {
|
|
|
|
type: REBLOG_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-01 07:21:48 -04:00
|
|
|
|
|
|
|
export function reblogFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: REBLOG_FAIL,
|
|
|
|
status: status,
|
2017-05-20 11:31:47 -04:00
|
|
|
error: error,
|
2016-09-01 07:21:48 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-01 07:21:48 -04:00
|
|
|
|
2016-10-02 09:14:26 -04:00
|
|
|
export function unreblogRequest(status) {
|
|
|
|
return {
|
|
|
|
type: UNREBLOG_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
status: status,
|
2016-10-02 09:14:26 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-10-02 09:14:26 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function unreblogSuccess(status) {
|
2016-10-02 09:14:26 -04:00
|
|
|
return {
|
|
|
|
type: UNREBLOG_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-10-02 09:14:26 -04:00
|
|
|
|
|
|
|
export function unreblogFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: UNREBLOG_FAIL,
|
|
|
|
status: status,
|
2017-05-20 11:31:47 -04:00
|
|
|
error: error,
|
2016-10-02 09:14:26 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-10-02 09:14:26 -04:00
|
|
|
|
2016-09-01 07:21:48 -04:00
|
|
|
export function favourite(status) {
|
|
|
|
return function (dispatch, getState) {
|
|
|
|
dispatch(favouriteRequest(status));
|
|
|
|
|
2016-09-27 10:58:23 -04:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then(function (response) {
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
dispatch(favouriteSuccess(status));
|
2016-09-01 07:21:48 -04:00
|
|
|
}).catch(function (error) {
|
|
|
|
dispatch(favouriteFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-01 07:21:48 -04:00
|
|
|
|
2016-09-26 17:55:21 -04:00
|
|
|
export function unfavourite(status) {
|
|
|
|
return (dispatch, getState) => {
|
2016-10-02 09:14:26 -04:00
|
|
|
dispatch(unfavouriteRequest(status));
|
|
|
|
|
2016-09-27 10:58:23 -04:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
dispatch(unfavouriteSuccess(status));
|
2016-09-26 17:55:21 -04:00
|
|
|
}).catch(error => {
|
2016-10-02 09:14:26 -04:00
|
|
|
dispatch(unfavouriteFail(status, error));
|
2016-09-26 17:55:21 -04:00
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-26 17:55:21 -04:00
|
|
|
|
2016-09-01 07:21:48 -04:00
|
|
|
export function favouriteRequest(status) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITE_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
status: status,
|
2016-09-01 07:21:48 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-01 07:21:48 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function favouriteSuccess(status) {
|
2016-09-01 07:21:48 -04:00
|
|
|
return {
|
|
|
|
type: FAVOURITE_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-09-01 07:21:48 -04:00
|
|
|
|
|
|
|
export function favouriteFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITE_FAIL,
|
|
|
|
status: status,
|
2017-05-20 11:31:47 -04:00
|
|
|
error: error,
|
2016-09-01 07:21:48 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-10-02 09:14:26 -04:00
|
|
|
|
|
|
|
export function unfavouriteRequest(status) {
|
|
|
|
return {
|
|
|
|
type: UNFAVOURITE_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
status: status,
|
2016-10-02 09:14:26 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-10-02 09:14:26 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function unfavouriteSuccess(status) {
|
2016-10-02 09:14:26 -04:00
|
|
|
return {
|
|
|
|
type: UNFAVOURITE_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-10-02 09:14:26 -04:00
|
|
|
|
|
|
|
export function unfavouriteFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: UNFAVOURITE_FAIL,
|
|
|
|
status: status,
|
2017-05-20 11:31:47 -04:00
|
|
|
error: error,
|
2016-10-02 09:14:26 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-03 15:16:14 -04:00
|
|
|
|
2018-04-11 13:42:25 -04:00
|
|
|
export function bookmark(status) {
|
|
|
|
return function (dispatch, getState) {
|
|
|
|
dispatch(bookmarkRequest(status));
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/bookmark`).then(function (response) {
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
dispatch(bookmarkSuccess(status));
|
2018-04-11 13:42:25 -04:00
|
|
|
}).catch(function (error) {
|
|
|
|
dispatch(bookmarkFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
|
|
|
export function unbookmark(status) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(unbookmarkRequest(status));
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/unbookmark`).then(response => {
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
dispatch(unbookmarkSuccess(status));
|
2018-04-11 13:42:25 -04:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch(unbookmarkFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
|
|
|
export function bookmarkRequest(status) {
|
|
|
|
return {
|
|
|
|
type: BOOKMARK_REQUEST,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function bookmarkSuccess(status) {
|
2018-04-11 13:42:25 -04:00
|
|
|
return {
|
|
|
|
type: BOOKMARK_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
|
|
|
export function bookmarkFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: BOOKMARK_FAIL,
|
|
|
|
status: status,
|
|
|
|
error: error,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
|
|
|
export function unbookmarkRequest(status) {
|
|
|
|
return {
|
|
|
|
type: UNBOOKMARK_REQUEST,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function unbookmarkSuccess(status) {
|
2018-04-11 13:42:25 -04:00
|
|
|
return {
|
|
|
|
type: UNBOOKMARK_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
|
|
|
export function unbookmarkFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: UNBOOKMARK_FAIL,
|
|
|
|
status: status,
|
|
|
|
error: error,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2018-04-11 13:42:25 -04:00
|
|
|
|
2016-11-03 15:16:14 -04:00
|
|
|
export function fetchReblogs(id) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(fetchReblogsRequest(id));
|
|
|
|
|
|
|
|
api(getState).get(`/api/v1/statuses/${id}/reblogged_by`).then(response => {
|
2023-08-29 08:42:20 -04:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedAccounts(response.data));
|
2023-08-29 08:42:20 -04:00
|
|
|
dispatch(fetchReblogsSuccess(id, response.data, next ? next.uri : null));
|
|
|
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
2016-11-03 15:16:14 -04:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch(fetchReblogsFail(id, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-03 15:16:14 -04:00
|
|
|
|
|
|
|
export function fetchReblogsRequest(id) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_FETCH_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
id,
|
2016-11-03 15:16:14 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-03 15:16:14 -04:00
|
|
|
|
2023-08-29 08:42:20 -04:00
|
|
|
export function fetchReblogsSuccess(id, accounts, next) {
|
2016-11-03 15:16:14 -04:00
|
|
|
return {
|
|
|
|
type: REBLOGS_FETCH_SUCCESS,
|
|
|
|
id,
|
2017-05-20 11:31:47 -04:00
|
|
|
accounts,
|
2023-08-29 08:42:20 -04:00
|
|
|
next,
|
2016-11-03 15:16:14 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-03 15:16:14 -04:00
|
|
|
|
|
|
|
export function fetchReblogsFail(id, error) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_FETCH_FAIL,
|
2023-08-29 08:42:20 -04:00
|
|
|
id,
|
|
|
|
error,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandReblogs(id) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const url = getState().getIn(['user_lists', 'reblogged_by', id, 'next']);
|
|
|
|
if (url === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(expandReblogsRequest(id));
|
|
|
|
|
|
|
|
api(getState).get(url).then(response => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(response.data));
|
|
|
|
dispatch(expandReblogsSuccess(id, response.data, next ? next.uri : null));
|
|
|
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
|
|
|
}).catch(error => dispatch(expandReblogsFail(id, error)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandReblogsRequest(id) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_EXPAND_REQUEST,
|
|
|
|
id,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandReblogsSuccess(id, accounts, next) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_EXPAND_SUCCESS,
|
|
|
|
id,
|
|
|
|
accounts,
|
|
|
|
next,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandReblogsFail(id, error) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_EXPAND_FAIL,
|
|
|
|
id,
|
2017-05-20 11:31:47 -04:00
|
|
|
error,
|
2016-11-03 15:16:14 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-04 08:39:24 -04:00
|
|
|
|
|
|
|
export function fetchFavourites(id) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(fetchFavouritesRequest(id));
|
|
|
|
|
|
|
|
api(getState).get(`/api/v1/statuses/${id}/favourited_by`).then(response => {
|
2023-08-29 04:56:19 -04:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedAccounts(response.data));
|
2023-08-29 04:56:19 -04:00
|
|
|
dispatch(fetchFavouritesSuccess(id, response.data, next ? next.uri : null));
|
|
|
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
2016-11-04 08:39:24 -04:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch(fetchFavouritesFail(id, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-04 08:39:24 -04:00
|
|
|
|
|
|
|
export function fetchFavouritesRequest(id) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITES_FETCH_REQUEST,
|
2017-05-20 11:31:47 -04:00
|
|
|
id,
|
2016-11-04 08:39:24 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-04 08:39:24 -04:00
|
|
|
|
2023-08-29 04:56:19 -04:00
|
|
|
export function fetchFavouritesSuccess(id, accounts, next) {
|
2016-11-04 08:39:24 -04:00
|
|
|
return {
|
|
|
|
type: FAVOURITES_FETCH_SUCCESS,
|
|
|
|
id,
|
2017-05-20 11:31:47 -04:00
|
|
|
accounts,
|
2023-08-29 04:56:19 -04:00
|
|
|
next,
|
2016-11-04 08:39:24 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2016-11-04 08:39:24 -04:00
|
|
|
|
|
|
|
export function fetchFavouritesFail(id, error) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITES_FETCH_FAIL,
|
2023-08-29 04:56:19 -04:00
|
|
|
id,
|
|
|
|
error,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandFavourites(id) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const url = getState().getIn(['user_lists', 'favourited_by', id, 'next']);
|
|
|
|
if (url === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(expandFavouritesRequest(id));
|
|
|
|
|
|
|
|
api(getState).get(url).then(response => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(response.data));
|
|
|
|
dispatch(expandFavouritesSuccess(id, response.data, next ? next.uri : null));
|
|
|
|
dispatch(fetchRelationships(response.data.map(item => item.id)));
|
|
|
|
}).catch(error => dispatch(expandFavouritesFail(id, error)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandFavouritesRequest(id) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITES_EXPAND_REQUEST,
|
|
|
|
id,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandFavouritesSuccess(id, accounts, next) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITES_EXPAND_SUCCESS,
|
|
|
|
id,
|
|
|
|
accounts,
|
|
|
|
next,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expandFavouritesFail(id, error) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITES_EXPAND_FAIL,
|
|
|
|
id,
|
2017-05-20 11:31:47 -04:00
|
|
|
error,
|
2016-11-04 08:39:24 -04:00
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
|
|
|
export function pin(status) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(pinRequest(status));
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/pin`).then(response => {
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
dispatch(pinSuccess(status));
|
2017-08-24 19:41:18 -04:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch(pinFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
|
|
|
export function pinRequest(status) {
|
|
|
|
return {
|
|
|
|
type: PIN_REQUEST,
|
|
|
|
status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function pinSuccess(status) {
|
2017-08-24 19:41:18 -04:00
|
|
|
return {
|
|
|
|
type: PIN_SUCCESS,
|
|
|
|
status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
|
|
|
export function pinFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: PIN_FAIL,
|
|
|
|
status,
|
|
|
|
error,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
|
|
|
export function unpin (status) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(unpinRequest(status));
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/unpin`).then(response => {
|
2019-03-05 14:15:43 -05:00
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
dispatch(unpinSuccess(status));
|
2017-08-24 19:41:18 -04:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch(unpinFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
|
|
|
export function unpinRequest(status) {
|
|
|
|
return {
|
|
|
|
type: UNPIN_REQUEST,
|
|
|
|
status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
2019-03-05 14:15:43 -05:00
|
|
|
export function unpinSuccess(status) {
|
2017-08-24 19:41:18 -04:00
|
|
|
return {
|
|
|
|
type: UNPIN_SUCCESS,
|
|
|
|
status,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|
2017-08-24 19:41:18 -04:00
|
|
|
|
|
|
|
export function unpinFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: UNPIN_FAIL,
|
|
|
|
status,
|
|
|
|
error,
|
|
|
|
};
|
2023-02-03 14:52:07 -05:00
|
|
|
}
|