]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/actions/interactions.js
Restore vanilla components
[mastodon.git] / app / javascript / mastodon / actions / interactions.js
1 import api from '../api';
2
3 export const REBLOG_REQUEST = 'REBLOG_REQUEST';
4 export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
5 export const REBLOG_FAIL = 'REBLOG_FAIL';
6
7 export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
8 export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
9 export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
10
11 export const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST';
12 export const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS';
13 export const UNREBLOG_FAIL = 'UNREBLOG_FAIL';
14
15 export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST';
16 export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS';
17 export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL';
18
19 export const REBLOGS_FETCH_REQUEST = 'REBLOGS_FETCH_REQUEST';
20 export const REBLOGS_FETCH_SUCCESS = 'REBLOGS_FETCH_SUCCESS';
21 export const REBLOGS_FETCH_FAIL = 'REBLOGS_FETCH_FAIL';
22
23 export const FAVOURITES_FETCH_REQUEST = 'FAVOURITES_FETCH_REQUEST';
24 export const FAVOURITES_FETCH_SUCCESS = 'FAVOURITES_FETCH_SUCCESS';
25 export const FAVOURITES_FETCH_FAIL = 'FAVOURITES_FETCH_FAIL';
26
27 export const PIN_REQUEST = 'PIN_REQUEST';
28 export const PIN_SUCCESS = 'PIN_SUCCESS';
29 export const PIN_FAIL = 'PIN_FAIL';
30
31 export const UNPIN_REQUEST = 'UNPIN_REQUEST';
32 export const UNPIN_SUCCESS = 'UNPIN_SUCCESS';
33 export const UNPIN_FAIL = 'UNPIN_FAIL';
34
35 export function reblog(status) {
36 return function (dispatch, getState) {
37 dispatch(reblogRequest(status));
38
39 api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then(function (response) {
40 // The reblog API method returns a new status wrapped around the original. In this case we are only
41 // interested in how the original is modified, hence passing it skipping the wrapper
42 dispatch(reblogSuccess(status, response.data.reblog));
43 }).catch(function (error) {
44 dispatch(reblogFail(status, error));
45 });
46 };
47 };
48
49 export function unreblog(status) {
50 return (dispatch, getState) => {
51 dispatch(unreblogRequest(status));
52
53 api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
54 dispatch(unreblogSuccess(status, response.data));
55 }).catch(error => {
56 dispatch(unreblogFail(status, error));
57 });
58 };
59 };
60
61 export function reblogRequest(status) {
62 return {
63 type: REBLOG_REQUEST,
64 status: status,
65 };
66 };
67
68 export function reblogSuccess(status, response) {
69 return {
70 type: REBLOG_SUCCESS,
71 status: status,
72 response: response,
73 };
74 };
75
76 export function reblogFail(status, error) {
77 return {
78 type: REBLOG_FAIL,
79 status: status,
80 error: error,
81 };
82 };
83
84 export function unreblogRequest(status) {
85 return {
86 type: UNREBLOG_REQUEST,
87 status: status,
88 };
89 };
90
91 export function unreblogSuccess(status, response) {
92 return {
93 type: UNREBLOG_SUCCESS,
94 status: status,
95 response: response,
96 };
97 };
98
99 export function unreblogFail(status, error) {
100 return {
101 type: UNREBLOG_FAIL,
102 status: status,
103 error: error,
104 };
105 };
106
107 export function favourite(status) {
108 return function (dispatch, getState) {
109 dispatch(favouriteRequest(status));
110
111 api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then(function (response) {
112 dispatch(favouriteSuccess(status, response.data));
113 }).catch(function (error) {
114 dispatch(favouriteFail(status, error));
115 });
116 };
117 };
118
119 export function unfavourite(status) {
120 return (dispatch, getState) => {
121 dispatch(unfavouriteRequest(status));
122
123 api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
124 dispatch(unfavouriteSuccess(status, response.data));
125 }).catch(error => {
126 dispatch(unfavouriteFail(status, error));
127 });
128 };
129 };
130
131 export function favouriteRequest(status) {
132 return {
133 type: FAVOURITE_REQUEST,
134 status: status,
135 };
136 };
137
138 export function favouriteSuccess(status, response) {
139 return {
140 type: FAVOURITE_SUCCESS,
141 status: status,
142 response: response,
143 };
144 };
145
146 export function favouriteFail(status, error) {
147 return {
148 type: FAVOURITE_FAIL,
149 status: status,
150 error: error,
151 };
152 };
153
154 export function unfavouriteRequest(status) {
155 return {
156 type: UNFAVOURITE_REQUEST,
157 status: status,
158 };
159 };
160
161 export function unfavouriteSuccess(status, response) {
162 return {
163 type: UNFAVOURITE_SUCCESS,
164 status: status,
165 response: response,
166 };
167 };
168
169 export function unfavouriteFail(status, error) {
170 return {
171 type: UNFAVOURITE_FAIL,
172 status: status,
173 error: error,
174 };
175 };
176
177 export function fetchReblogs(id) {
178 return (dispatch, getState) => {
179 dispatch(fetchReblogsRequest(id));
180
181 api(getState).get(`/api/v1/statuses/${id}/reblogged_by`).then(response => {
182 dispatch(fetchReblogsSuccess(id, response.data));
183 }).catch(error => {
184 dispatch(fetchReblogsFail(id, error));
185 });
186 };
187 };
188
189 export function fetchReblogsRequest(id) {
190 return {
191 type: REBLOGS_FETCH_REQUEST,
192 id,
193 };
194 };
195
196 export function fetchReblogsSuccess(id, accounts) {
197 return {
198 type: REBLOGS_FETCH_SUCCESS,
199 id,
200 accounts,
201 };
202 };
203
204 export function fetchReblogsFail(id, error) {
205 return {
206 type: REBLOGS_FETCH_FAIL,
207 error,
208 };
209 };
210
211 export function fetchFavourites(id) {
212 return (dispatch, getState) => {
213 dispatch(fetchFavouritesRequest(id));
214
215 api(getState).get(`/api/v1/statuses/${id}/favourited_by`).then(response => {
216 dispatch(fetchFavouritesSuccess(id, response.data));
217 }).catch(error => {
218 dispatch(fetchFavouritesFail(id, error));
219 });
220 };
221 };
222
223 export function fetchFavouritesRequest(id) {
224 return {
225 type: FAVOURITES_FETCH_REQUEST,
226 id,
227 };
228 };
229
230 export function fetchFavouritesSuccess(id, accounts) {
231 return {
232 type: FAVOURITES_FETCH_SUCCESS,
233 id,
234 accounts,
235 };
236 };
237
238 export function fetchFavouritesFail(id, error) {
239 return {
240 type: FAVOURITES_FETCH_FAIL,
241 error,
242 };
243 };
244
245 export function pin(status) {
246 return (dispatch, getState) => {
247 dispatch(pinRequest(status));
248
249 api(getState).post(`/api/v1/statuses/${status.get('id')}/pin`).then(response => {
250 dispatch(pinSuccess(status, response.data));
251 }).catch(error => {
252 dispatch(pinFail(status, error));
253 });
254 };
255 };
256
257 export function pinRequest(status) {
258 return {
259 type: PIN_REQUEST,
260 status,
261 };
262 };
263
264 export function pinSuccess(status, response) {
265 return {
266 type: PIN_SUCCESS,
267 status,
268 response,
269 };
270 };
271
272 export function pinFail(status, error) {
273 return {
274 type: PIN_FAIL,
275 status,
276 error,
277 };
278 };
279
280 export function unpin (status) {
281 return (dispatch, getState) => {
282 dispatch(unpinRequest(status));
283
284 api(getState).post(`/api/v1/statuses/${status.get('id')}/unpin`).then(response => {
285 dispatch(unpinSuccess(status, response.data));
286 }).catch(error => {
287 dispatch(unpinFail(status, error));
288 });
289 };
290 };
291
292 export function unpinRequest(status) {
293 return {
294 type: UNPIN_REQUEST,
295 status,
296 };
297 };
298
299 export function unpinSuccess(status, response) {
300 return {
301 type: UNPIN_SUCCESS,
302 status,
303 response,
304 };
305 };
306
307 export function unpinFail(status, error) {
308 return {
309 type: UNPIN_FAIL,
310 status,
311 error,
312 };
313 };
This page took 0.190422 seconds and 4 git commands to generate.