2016-09-01 20:21:48 +09:00
|
|
|
import api from '../api'
|
|
|
|
|
|
|
|
export const REBLOG_REQUEST = 'REBLOG_REQUEST';
|
|
|
|
export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
|
|
|
|
export const REBLOG_FAIL = 'REBLOG_FAIL';
|
|
|
|
|
|
|
|
export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
|
|
|
|
export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
|
|
|
|
export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
|
|
|
|
|
2016-10-02 22:14:26 +09: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-04 04:16:14 +09: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 20:48:53 +09: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';
|
|
|
|
|
2016-09-01 20:21:48 +09:00
|
|
|
export function reblog(status) {
|
|
|
|
return function (dispatch, getState) {
|
|
|
|
dispatch(reblogRequest(status));
|
|
|
|
|
2016-09-27 23:58:23 +09:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then(function (response) {
|
2016-09-01 21:12:11 +09: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
|
|
|
|
dispatch(reblogSuccess(status, response.data.reblog));
|
2016-09-01 20:21:48 +09:00
|
|
|
}).catch(function (error) {
|
|
|
|
dispatch(reblogFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-09-01 20:21:48 +09:00
|
|
|
|
2016-09-27 06:55:21 +09:00
|
|
|
export function unreblog(status) {
|
|
|
|
return (dispatch, getState) => {
|
2016-10-02 22:14:26 +09:00
|
|
|
dispatch(unreblogRequest(status));
|
|
|
|
|
2016-09-27 23:58:23 +09:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
|
2016-10-02 22:14:26 +09:00
|
|
|
dispatch(unreblogSuccess(status, response.data));
|
2016-09-27 06:55:21 +09:00
|
|
|
}).catch(error => {
|
2016-10-02 22:14:26 +09:00
|
|
|
dispatch(unreblogFail(status, error));
|
2016-09-27 06:55:21 +09:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-09-01 20:21:48 +09:00
|
|
|
export function reblogRequest(status) {
|
|
|
|
return {
|
|
|
|
type: REBLOG_REQUEST,
|
|
|
|
status: status
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-09-01 20:21:48 +09:00
|
|
|
|
|
|
|
export function reblogSuccess(status, response) {
|
|
|
|
return {
|
|
|
|
type: REBLOG_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
response: response
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-09-01 20:21:48 +09:00
|
|
|
|
|
|
|
export function reblogFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: REBLOG_FAIL,
|
|
|
|
status: status,
|
|
|
|
error: error
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-09-01 20:21:48 +09:00
|
|
|
|
2016-10-02 22:14:26 +09:00
|
|
|
export function unreblogRequest(status) {
|
|
|
|
return {
|
|
|
|
type: UNREBLOG_REQUEST,
|
|
|
|
status: status
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function unreblogSuccess(status, response) {
|
|
|
|
return {
|
|
|
|
type: UNREBLOG_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
response: response
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function unreblogFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: UNREBLOG_FAIL,
|
|
|
|
status: status,
|
|
|
|
error: error
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-09-01 20:21:48 +09:00
|
|
|
export function favourite(status) {
|
|
|
|
return function (dispatch, getState) {
|
|
|
|
dispatch(favouriteRequest(status));
|
|
|
|
|
2016-09-27 23:58:23 +09:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then(function (response) {
|
2016-09-01 20:21:48 +09:00
|
|
|
dispatch(favouriteSuccess(status, response.data));
|
|
|
|
}).catch(function (error) {
|
|
|
|
dispatch(favouriteFail(status, error));
|
|
|
|
});
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-09-01 20:21:48 +09:00
|
|
|
|
2016-09-27 06:55:21 +09:00
|
|
|
export function unfavourite(status) {
|
|
|
|
return (dispatch, getState) => {
|
2016-10-02 22:14:26 +09:00
|
|
|
dispatch(unfavouriteRequest(status));
|
|
|
|
|
2016-09-27 23:58:23 +09:00
|
|
|
api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
|
2016-10-02 22:14:26 +09:00
|
|
|
dispatch(unfavouriteSuccess(status, response.data));
|
2016-09-27 06:55:21 +09:00
|
|
|
}).catch(error => {
|
2016-10-02 22:14:26 +09:00
|
|
|
dispatch(unfavouriteFail(status, error));
|
2016-09-27 06:55:21 +09:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-09-01 20:21:48 +09:00
|
|
|
export function favouriteRequest(status) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITE_REQUEST,
|
|
|
|
status: status
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-09-01 20:21:48 +09:00
|
|
|
|
|
|
|
export function favouriteSuccess(status, response) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITE_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
response: response
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-09-01 20:21:48 +09:00
|
|
|
|
|
|
|
export function favouriteFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: FAVOURITE_FAIL,
|
|
|
|
status: status,
|
|
|
|
error: error
|
|
|
|
};
|
2016-09-13 02:20:55 +09:00
|
|
|
};
|
2016-10-02 22:14:26 +09:00
|
|
|
|
|
|
|
export function unfavouriteRequest(status) {
|
|
|
|
return {
|
|
|
|
type: UNFAVOURITE_REQUEST,
|
|
|
|
status: status
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function unfavouriteSuccess(status, response) {
|
|
|
|
return {
|
|
|
|
type: UNFAVOURITE_SUCCESS,
|
|
|
|
status: status,
|
|
|
|
response: response
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function unfavouriteFail(status, error) {
|
|
|
|
return {
|
|
|
|
type: UNFAVOURITE_FAIL,
|
|
|
|
status: status,
|
|
|
|
error: error
|
|
|
|
};
|
|
|
|
};
|
2016-11-04 04:16:14 +09:00
|
|
|
|
|
|
|
export function fetchReblogs(id) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(fetchReblogsRequest(id));
|
|
|
|
|
|
|
|
api(getState).get(`/api/v1/statuses/${id}/reblogged_by`).then(response => {
|
|
|
|
dispatch(fetchReblogsSuccess(id, response.data));
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch(fetchReblogsFail(id, error));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function fetchReblogsRequest(id) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_FETCH_REQUEST,
|
|
|
|
id
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function fetchReblogsSuccess(id, accounts) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_FETCH_SUCCESS,
|
|
|
|
id,
|
|
|
|
accounts
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export function fetchReblogsFail(id, error) {
|
|
|
|
return {
|
|
|
|
type: REBLOGS_FETCH_FAIL,
|
|
|
|
error
|
|
|
|
};
|
|
|
|
};
|