]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/flavours/glitch/actions/statuses.js
1 import api
from 'flavours/glitch/util/api';
3 import { deleteFromTimelines
} from './timelines';
5 export const STATUS_FETCH_REQUEST
= 'STATUS_FETCH_REQUEST';
6 export const STATUS_FETCH_SUCCESS
= 'STATUS_FETCH_SUCCESS';
7 export const STATUS_FETCH_FAIL
= 'STATUS_FETCH_FAIL';
9 export const STATUS_DELETE_REQUEST
= 'STATUS_DELETE_REQUEST';
10 export const STATUS_DELETE_SUCCESS
= 'STATUS_DELETE_SUCCESS';
11 export const STATUS_DELETE_FAIL
= 'STATUS_DELETE_FAIL';
13 export const CONTEXT_FETCH_REQUEST
= 'CONTEXT_FETCH_REQUEST';
14 export const CONTEXT_FETCH_SUCCESS
= 'CONTEXT_FETCH_SUCCESS';
15 export const CONTEXT_FETCH_FAIL
= 'CONTEXT_FETCH_FAIL';
17 export const STATUS_MUTE_REQUEST
= 'STATUS_MUTE_REQUEST';
18 export const STATUS_MUTE_SUCCESS
= 'STATUS_MUTE_SUCCESS';
19 export const STATUS_MUTE_FAIL
= 'STATUS_MUTE_FAIL';
21 export const STATUS_UNMUTE_REQUEST
= 'STATUS_UNMUTE_REQUEST';
22 export const STATUS_UNMUTE_SUCCESS
= 'STATUS_UNMUTE_SUCCESS';
23 export const STATUS_UNMUTE_FAIL
= 'STATUS_UNMUTE_FAIL';
25 export const REDRAFT
= 'REDRAFT';
27 export function fetchStatusRequest(id
, skipLoading
) {
29 type: STATUS_FETCH_REQUEST
,
35 export function fetchStatus(id
) {
36 return (dispatch
, getState
) => {
37 const skipLoading
= getState().getIn(['statuses', id
], null) !== null;
39 dispatch(fetchContext(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 redraft(status
) {
80 export function deleteStatus(id
, router
, withRedraft
= false) {
81 return (dispatch
, getState
) => {
82 const status
= getState().getIn(['statuses', id
]);
84 dispatch(deleteStatusRequest(id
));
86 api(getState
).delete(`/api/v1/statuses/${id}`).then(() => {
87 dispatch(deleteStatusSuccess(id
));
88 dispatch(deleteFromTimelines(id
));
91 dispatch(redraft(status
));
93 if (!getState().getIn(['compose', 'mounted'])) {
94 router
.push('/statuses/new');
98 dispatch(deleteStatusFail(id
, error
));
103 export function deleteStatusRequest(id
) {
105 type: STATUS_DELETE_REQUEST
,
110 export function deleteStatusSuccess(id
) {
112 type: STATUS_DELETE_SUCCESS
,
117 export function deleteStatusFail(id
, error
) {
119 type: STATUS_DELETE_FAIL
,
125 export function fetchContext(id
) {
126 return (dispatch
, getState
) => {
127 dispatch(fetchContextRequest(id
));
129 api(getState
).get(`/api/v1/statuses/${id}/context`).then(response
=> {
130 dispatch(fetchContextSuccess(id
, response
.data
.ancestors
, response
.data
.descendants
));
133 if (error
.response
&& error
.response
.status
=== 404) {
134 dispatch(deleteFromTimelines(id
));
137 dispatch(fetchContextFail(id
, error
));
142 export function fetchContextRequest(id
) {
144 type: CONTEXT_FETCH_REQUEST
,
149 export function fetchContextSuccess(id
, ancestors
, descendants
) {
151 type: CONTEXT_FETCH_SUCCESS
,
155 statuses: ancestors
.concat(descendants
),
159 export function fetchContextFail(id
, error
) {
161 type: CONTEXT_FETCH_FAIL
,
168 export function muteStatus(id
) {
169 return (dispatch
, getState
) => {
170 dispatch(muteStatusRequest(id
));
172 api(getState
).post(`/api/v1/statuses/${id}/mute`).then(() => {
173 dispatch(muteStatusSuccess(id
));
175 dispatch(muteStatusFail(id
, error
));
180 export function muteStatusRequest(id
) {
182 type: STATUS_MUTE_REQUEST
,
187 export function muteStatusSuccess(id
) {
189 type: STATUS_MUTE_SUCCESS
,
194 export function muteStatusFail(id
, error
) {
196 type: STATUS_MUTE_FAIL
,
202 export function unmuteStatus(id
) {
203 return (dispatch
, getState
) => {
204 dispatch(unmuteStatusRequest(id
));
206 api(getState
).post(`/api/v1/statuses/${id}/unmute`).then(() => {
207 dispatch(unmuteStatusSuccess(id
));
209 dispatch(unmuteStatusFail(id
, error
));
214 export function unmuteStatusRequest(id
) {
216 type: STATUS_UNMUTE_REQUEST
,
221 export function unmuteStatusSuccess(id
) {
223 type: STATUS_UNMUTE_SUCCESS
,
228 export function unmuteStatusFail(id
, error
) {
230 type: STATUS_UNMUTE_FAIL
,
This page took 0.273152 seconds and 4 git commands to generate.