]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/actions/statuses.js
Restore vanilla components
[mastodon.git] / app / javascript / mastodon / actions / statuses.js
1 import api from '../api';
2
3 import { deleteFromTimelines } from './timelines';
4 import { fetchStatusCard } from './cards';
5
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';
9
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';
13
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';
17
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';
21
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';
25
26 export function fetchStatusRequest(id, skipLoading) {
27 return {
28 type: STATUS_FETCH_REQUEST,
29 id,
30 skipLoading,
31 };
32 };
33
34 export function fetchStatus(id) {
35 return (dispatch, getState) => {
36 const skipLoading = getState().getIn(['statuses', id], null) !== null;
37
38 dispatch(fetchContext(id));
39 dispatch(fetchStatusCard(id));
40
41 if (skipLoading) {
42 return;
43 }
44
45 dispatch(fetchStatusRequest(id, skipLoading));
46
47 api(getState).get(`/api/v1/statuses/${id}`).then(response => {
48 dispatch(fetchStatusSuccess(response.data, skipLoading));
49 }).catch(error => {
50 dispatch(fetchStatusFail(id, error, skipLoading));
51 });
52 };
53 };
54
55 export function fetchStatusSuccess(status, skipLoading) {
56 return {
57 type: STATUS_FETCH_SUCCESS,
58 status,
59 skipLoading,
60 };
61 };
62
63 export function fetchStatusFail(id, error, skipLoading) {
64 return {
65 type: STATUS_FETCH_FAIL,
66 id,
67 error,
68 skipLoading,
69 skipAlert: true,
70 };
71 };
72
73 export function deleteStatus(id) {
74 return (dispatch, getState) => {
75 dispatch(deleteStatusRequest(id));
76
77 api(getState).delete(`/api/v1/statuses/${id}`).then(() => {
78 dispatch(deleteStatusSuccess(id));
79 dispatch(deleteFromTimelines(id));
80 }).catch(error => {
81 dispatch(deleteStatusFail(id, error));
82 });
83 };
84 };
85
86 export function deleteStatusRequest(id) {
87 return {
88 type: STATUS_DELETE_REQUEST,
89 id: id,
90 };
91 };
92
93 export function deleteStatusSuccess(id) {
94 return {
95 type: STATUS_DELETE_SUCCESS,
96 id: id,
97 };
98 };
99
100 export function deleteStatusFail(id, error) {
101 return {
102 type: STATUS_DELETE_FAIL,
103 id: id,
104 error: error,
105 };
106 };
107
108 export function fetchContext(id) {
109 return (dispatch, getState) => {
110 dispatch(fetchContextRequest(id));
111
112 api(getState).get(`/api/v1/statuses/${id}/context`).then(response => {
113 dispatch(fetchContextSuccess(id, response.data.ancestors, response.data.descendants));
114
115 }).catch(error => {
116 if (error.response && error.response.status === 404) {
117 dispatch(deleteFromTimelines(id));
118 }
119
120 dispatch(fetchContextFail(id, error));
121 });
122 };
123 };
124
125 export function fetchContextRequest(id) {
126 return {
127 type: CONTEXT_FETCH_REQUEST,
128 id,
129 };
130 };
131
132 export function fetchContextSuccess(id, ancestors, descendants) {
133 return {
134 type: CONTEXT_FETCH_SUCCESS,
135 id,
136 ancestors,
137 descendants,
138 statuses: ancestors.concat(descendants),
139 };
140 };
141
142 export function fetchContextFail(id, error) {
143 return {
144 type: CONTEXT_FETCH_FAIL,
145 id,
146 error,
147 skipAlert: true,
148 };
149 };
150
151 export function muteStatus(id) {
152 return (dispatch, getState) => {
153 dispatch(muteStatusRequest(id));
154
155 api(getState).post(`/api/v1/statuses/${id}/mute`).then(() => {
156 dispatch(muteStatusSuccess(id));
157 }).catch(error => {
158 dispatch(muteStatusFail(id, error));
159 });
160 };
161 };
162
163 export function muteStatusRequest(id) {
164 return {
165 type: STATUS_MUTE_REQUEST,
166 id,
167 };
168 };
169
170 export function muteStatusSuccess(id) {
171 return {
172 type: STATUS_MUTE_SUCCESS,
173 id,
174 };
175 };
176
177 export function muteStatusFail(id, error) {
178 return {
179 type: STATUS_MUTE_FAIL,
180 id,
181 error,
182 };
183 };
184
185 export function unmuteStatus(id) {
186 return (dispatch, getState) => {
187 dispatch(unmuteStatusRequest(id));
188
189 api(getState).post(`/api/v1/statuses/${id}/unmute`).then(() => {
190 dispatch(unmuteStatusSuccess(id));
191 }).catch(error => {
192 dispatch(unmuteStatusFail(id, error));
193 });
194 };
195 };
196
197 export function unmuteStatusRequest(id) {
198 return {
199 type: STATUS_UNMUTE_REQUEST,
200 id,
201 };
202 };
203
204 export function unmuteStatusSuccess(id) {
205 return {
206 type: STATUS_UNMUTE_SUCCESS,
207 id,
208 };
209 };
210
211 export function unmuteStatusFail(id, error) {
212 return {
213 type: STATUS_UNMUTE_FAIL,
214 id,
215 error,
216 };
217 };
This page took 0.13744 seconds and 4 git commands to generate.