]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/actions/statuses.js
1 import api
from '../api';
3 import { deleteFromTimelines
} from './timelines';
4 import { fetchStatusCard
} from './cards';
6 export const STATUS_FETCH_REQUEST
= 'STATUS_FETCH_REQUEST';
7 export const STATUS_FETCH_SUCCESS
= 'STATUS_FETCH_SUCCESS';
8 export const STATUS_FETCH_FAIL
= 'STATUS_FETCH_FAIL';
10 export const STATUS_DELETE_REQUEST
= 'STATUS_DELETE_REQUEST';
11 export const STATUS_DELETE_SUCCESS
= 'STATUS_DELETE_SUCCESS';
12 export const STATUS_DELETE_FAIL
= 'STATUS_DELETE_FAIL';
14 export const CONTEXT_FETCH_REQUEST
= 'CONTEXT_FETCH_REQUEST';
15 export const CONTEXT_FETCH_SUCCESS
= 'CONTEXT_FETCH_SUCCESS';
16 export const CONTEXT_FETCH_FAIL
= 'CONTEXT_FETCH_FAIL';
18 export const STATUS_MUTE_REQUEST
= 'STATUS_MUTE_REQUEST';
19 export const STATUS_MUTE_SUCCESS
= 'STATUS_MUTE_SUCCESS';
20 export const STATUS_MUTE_FAIL
= 'STATUS_MUTE_FAIL';
22 export const STATUS_UNMUTE_REQUEST
= 'STATUS_UNMUTE_REQUEST';
23 export const STATUS_UNMUTE_SUCCESS
= 'STATUS_UNMUTE_SUCCESS';
24 export const STATUS_UNMUTE_FAIL
= 'STATUS_UNMUTE_FAIL';
26 export function fetchStatusRequest(id
, skipLoading
) {
28 type: STATUS_FETCH_REQUEST
,
34 export function fetchStatus(id
) {
35 return (dispatch
, getState
) => {
36 const skipLoading
= getState().getIn(['statuses', id
], null) !== null;
38 dispatch(fetchContext(id
));
39 dispatch(fetchStatusCard(id
));
45 dispatch(fetchStatusRequest(id
, skipLoading
));
47 api(getState
).get(`/api/v1/statuses/${id}`).then(response
=> {
48 dispatch(fetchStatusSuccess(response
.data
, skipLoading
));
50 dispatch(fetchStatusFail(id
, error
, skipLoading
));
55 export function fetchStatusSuccess(status
, skipLoading
) {
57 type: STATUS_FETCH_SUCCESS
,
63 export function fetchStatusFail(id
, error
, skipLoading
) {
65 type: STATUS_FETCH_FAIL
,
73 export function deleteStatus(id
) {
74 return (dispatch
, getState
) => {
75 dispatch(deleteStatusRequest(id
));
77 api(getState
).delete(`/api/v1/statuses/${id}`).then(() => {
78 dispatch(deleteStatusSuccess(id
));
79 dispatch(deleteFromTimelines(id
));
81 dispatch(deleteStatusFail(id
, error
));
86 export function deleteStatusRequest(id
) {
88 type: STATUS_DELETE_REQUEST
,
93 export function deleteStatusSuccess(id
) {
95 type: STATUS_DELETE_SUCCESS
,
100 export function deleteStatusFail(id
, error
) {
102 type: STATUS_DELETE_FAIL
,
108 export function fetchContext(id
) {
109 return (dispatch
, getState
) => {
110 dispatch(fetchContextRequest(id
));
112 api(getState
).get(`/api/v1/statuses/${id}/context`).then(response
=> {
113 dispatch(fetchContextSuccess(id
, response
.data
.ancestors
, response
.data
.descendants
));
116 if (error
.response
&& error
.response
.status
=== 404) {
117 dispatch(deleteFromTimelines(id
));
120 dispatch(fetchContextFail(id
, error
));
125 export function fetchContextRequest(id
) {
127 type: CONTEXT_FETCH_REQUEST
,
132 export function fetchContextSuccess(id
, ancestors
, descendants
) {
134 type: CONTEXT_FETCH_SUCCESS
,
138 statuses: ancestors
.concat(descendants
),
142 export function fetchContextFail(id
, error
) {
144 type: CONTEXT_FETCH_FAIL
,
151 export function muteStatus(id
) {
152 return (dispatch
, getState
) => {
153 dispatch(muteStatusRequest(id
));
155 api(getState
).post(`/api/v1/statuses/${id}/mute`).then(() => {
156 dispatch(muteStatusSuccess(id
));
158 dispatch(muteStatusFail(id
, error
));
163 export function muteStatusRequest(id
) {
165 type: STATUS_MUTE_REQUEST
,
170 export function muteStatusSuccess(id
) {
172 type: STATUS_MUTE_SUCCESS
,
177 export function muteStatusFail(id
, error
) {
179 type: STATUS_MUTE_FAIL
,
185 export function unmuteStatus(id
) {
186 return (dispatch
, getState
) => {
187 dispatch(unmuteStatusRequest(id
));
189 api(getState
).post(`/api/v1/statuses/${id}/unmute`).then(() => {
190 dispatch(unmuteStatusSuccess(id
));
192 dispatch(unmuteStatusFail(id
, error
));
197 export function unmuteStatusRequest(id
) {
199 type: STATUS_UNMUTE_REQUEST
,
204 export function unmuteStatusSuccess(id
) {
206 type: STATUS_UNMUTE_SUCCESS
,
211 export function unmuteStatusFail(id
, error
) {
213 type: STATUS_UNMUTE_FAIL
,
This page took 0.13744 seconds and 4 git commands to generate.