]> cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/actions/accounts.js
Improve eslint rules (#3147)
[mastodon.git] / app / javascript / mastodon / actions / accounts.js
1 import api, { getLinks } from '../api';
2 import Immutable from 'immutable';
3
4 export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
5 export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS';
6 export const ACCOUNT_FETCH_FAIL = 'ACCOUNT_FETCH_FAIL';
7
8 export const ACCOUNT_FOLLOW_REQUEST = 'ACCOUNT_FOLLOW_REQUEST';
9 export const ACCOUNT_FOLLOW_SUCCESS = 'ACCOUNT_FOLLOW_SUCCESS';
10 export const ACCOUNT_FOLLOW_FAIL = 'ACCOUNT_FOLLOW_FAIL';
11
12 export const ACCOUNT_UNFOLLOW_REQUEST = 'ACCOUNT_UNFOLLOW_REQUEST';
13 export const ACCOUNT_UNFOLLOW_SUCCESS = 'ACCOUNT_UNFOLLOW_SUCCESS';
14 export const ACCOUNT_UNFOLLOW_FAIL = 'ACCOUNT_UNFOLLOW_FAIL';
15
16 export const ACCOUNT_BLOCK_REQUEST = 'ACCOUNT_BLOCK_REQUEST';
17 export const ACCOUNT_BLOCK_SUCCESS = 'ACCOUNT_BLOCK_SUCCESS';
18 export const ACCOUNT_BLOCK_FAIL = 'ACCOUNT_BLOCK_FAIL';
19
20 export const ACCOUNT_UNBLOCK_REQUEST = 'ACCOUNT_UNBLOCK_REQUEST';
21 export const ACCOUNT_UNBLOCK_SUCCESS = 'ACCOUNT_UNBLOCK_SUCCESS';
22 export const ACCOUNT_UNBLOCK_FAIL = 'ACCOUNT_UNBLOCK_FAIL';
23
24 export const ACCOUNT_MUTE_REQUEST = 'ACCOUNT_MUTE_REQUEST';
25 export const ACCOUNT_MUTE_SUCCESS = 'ACCOUNT_MUTE_SUCCESS';
26 export const ACCOUNT_MUTE_FAIL = 'ACCOUNT_MUTE_FAIL';
27
28 export const ACCOUNT_UNMUTE_REQUEST = 'ACCOUNT_UNMUTE_REQUEST';
29 export const ACCOUNT_UNMUTE_SUCCESS = 'ACCOUNT_UNMUTE_SUCCESS';
30 export const ACCOUNT_UNMUTE_FAIL = 'ACCOUNT_UNMUTE_FAIL';
31
32 export const ACCOUNT_TIMELINE_FETCH_REQUEST = 'ACCOUNT_TIMELINE_FETCH_REQUEST';
33 export const ACCOUNT_TIMELINE_FETCH_SUCCESS = 'ACCOUNT_TIMELINE_FETCH_SUCCESS';
34 export const ACCOUNT_TIMELINE_FETCH_FAIL = 'ACCOUNT_TIMELINE_FETCH_FAIL';
35
36 export const ACCOUNT_TIMELINE_EXPAND_REQUEST = 'ACCOUNT_TIMELINE_EXPAND_REQUEST';
37 export const ACCOUNT_TIMELINE_EXPAND_SUCCESS = 'ACCOUNT_TIMELINE_EXPAND_SUCCESS';
38 export const ACCOUNT_TIMELINE_EXPAND_FAIL = 'ACCOUNT_TIMELINE_EXPAND_FAIL';
39
40 export const ACCOUNT_MEDIA_TIMELINE_FETCH_REQUEST = 'ACCOUNT_MEDIA_TIMELINE_FETCH_REQUEST';
41 export const ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS = 'ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS';
42 export const ACCOUNT_MEDIA_TIMELINE_FETCH_FAIL = 'ACCOUNT_MEDIA_TIMELINE_FETCH_FAIL';
43
44 export const ACCOUNT_MEDIA_TIMELINE_EXPAND_REQUEST = 'ACCOUNT_MEDIA_TIMELINE_EXPAND_REQUEST';
45 export const ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS = 'ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS';
46 export const ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL = 'ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL';
47
48 export const FOLLOWERS_FETCH_REQUEST = 'FOLLOWERS_FETCH_REQUEST';
49 export const FOLLOWERS_FETCH_SUCCESS = 'FOLLOWERS_FETCH_SUCCESS';
50 export const FOLLOWERS_FETCH_FAIL = 'FOLLOWERS_FETCH_FAIL';
51
52 export const FOLLOWERS_EXPAND_REQUEST = 'FOLLOWERS_EXPAND_REQUEST';
53 export const FOLLOWERS_EXPAND_SUCCESS = 'FOLLOWERS_EXPAND_SUCCESS';
54 export const FOLLOWERS_EXPAND_FAIL = 'FOLLOWERS_EXPAND_FAIL';
55
56 export const FOLLOWING_FETCH_REQUEST = 'FOLLOWING_FETCH_REQUEST';
57 export const FOLLOWING_FETCH_SUCCESS = 'FOLLOWING_FETCH_SUCCESS';
58 export const FOLLOWING_FETCH_FAIL = 'FOLLOWING_FETCH_FAIL';
59
60 export const FOLLOWING_EXPAND_REQUEST = 'FOLLOWING_EXPAND_REQUEST';
61 export const FOLLOWING_EXPAND_SUCCESS = 'FOLLOWING_EXPAND_SUCCESS';
62 export const FOLLOWING_EXPAND_FAIL = 'FOLLOWING_EXPAND_FAIL';
63
64 export const RELATIONSHIPS_FETCH_REQUEST = 'RELATIONSHIPS_FETCH_REQUEST';
65 export const RELATIONSHIPS_FETCH_SUCCESS = 'RELATIONSHIPS_FETCH_SUCCESS';
66 export const RELATIONSHIPS_FETCH_FAIL = 'RELATIONSHIPS_FETCH_FAIL';
67
68 export const FOLLOW_REQUESTS_FETCH_REQUEST = 'FOLLOW_REQUESTS_FETCH_REQUEST';
69 export const FOLLOW_REQUESTS_FETCH_SUCCESS = 'FOLLOW_REQUESTS_FETCH_SUCCESS';
70 export const FOLLOW_REQUESTS_FETCH_FAIL = 'FOLLOW_REQUESTS_FETCH_FAIL';
71
72 export const FOLLOW_REQUESTS_EXPAND_REQUEST = 'FOLLOW_REQUESTS_EXPAND_REQUEST';
73 export const FOLLOW_REQUESTS_EXPAND_SUCCESS = 'FOLLOW_REQUESTS_EXPAND_SUCCESS';
74 export const FOLLOW_REQUESTS_EXPAND_FAIL = 'FOLLOW_REQUESTS_EXPAND_FAIL';
75
76 export const FOLLOW_REQUEST_AUTHORIZE_REQUEST = 'FOLLOW_REQUEST_AUTHORIZE_REQUEST';
77 export const FOLLOW_REQUEST_AUTHORIZE_SUCCESS = 'FOLLOW_REQUEST_AUTHORIZE_SUCCESS';
78 export const FOLLOW_REQUEST_AUTHORIZE_FAIL = 'FOLLOW_REQUEST_AUTHORIZE_FAIL';
79
80 export const FOLLOW_REQUEST_REJECT_REQUEST = 'FOLLOW_REQUEST_REJECT_REQUEST';
81 export const FOLLOW_REQUEST_REJECT_SUCCESS = 'FOLLOW_REQUEST_REJECT_SUCCESS';
82 export const FOLLOW_REQUEST_REJECT_FAIL = 'FOLLOW_REQUEST_REJECT_FAIL';
83
84 export function fetchAccount(id) {
85 return (dispatch, getState) => {
86 dispatch(fetchRelationships([id]));
87
88 if (getState().getIn(['accounts', id], null) !== null) {
89 return;
90 }
91
92 dispatch(fetchAccountRequest(id));
93
94 api(getState).get(`/api/v1/accounts/${id}`).then(response => {
95 dispatch(fetchAccountSuccess(response.data));
96 }).catch(error => {
97 dispatch(fetchAccountFail(id, error));
98 });
99 };
100 };
101
102 export function fetchAccountTimeline(id, replace = false) {
103 return (dispatch, getState) => {
104 const ids = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List());
105 const newestId = ids.size > 0 ? ids.first() : null;
106
107 let params = {};
108 let skipLoading = false;
109
110 if (newestId !== null && !replace) {
111 params.since_id = newestId;
112 skipLoading = true;
113 }
114
115 dispatch(fetchAccountTimelineRequest(id, skipLoading));
116
117 api(getState).get(`/api/v1/accounts/${id}/statuses`, { params }).then(response => {
118 dispatch(fetchAccountTimelineSuccess(id, response.data, replace, skipLoading));
119 }).catch(error => {
120 dispatch(fetchAccountTimelineFail(id, error, skipLoading));
121 });
122 };
123 };
124
125 export function fetchAccountMediaTimeline(id, replace = false) {
126 return (dispatch, getState) => {
127 const ids = getState().getIn(['timelines', 'accounts_media_timelines', id, 'items'], Immutable.List());
128 const newestId = ids.size > 0 ? ids.first() : null;
129
130 let params = { only_media: 'true', limit: 12 };
131 let skipLoading = false;
132
133 if (newestId !== null && !replace) {
134 params.since_id = newestId;
135 skipLoading = true;
136 }
137
138 dispatch(fetchAccountMediaTimelineRequest(id, skipLoading));
139
140 api(getState).get(`/api/v1/accounts/${id}/statuses`, { params }).then(response => {
141 dispatch(fetchAccountMediaTimelineSuccess(id, response.data, replace, skipLoading));
142 }).catch(error => {
143 dispatch(fetchAccountMediaTimelineFail(id, error, skipLoading));
144 });
145 };
146 };
147
148 export function expandAccountTimeline(id) {
149 return (dispatch, getState) => {
150 const lastId = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List()).last();
151
152 dispatch(expandAccountTimelineRequest(id));
153
154 api(getState).get(`/api/v1/accounts/${id}/statuses`, {
155 params: {
156 limit: 10,
157 max_id: lastId,
158 },
159 }).then(response => {
160 const next = getLinks(response).refs.find(link => link.rel === 'next');
161 dispatch(expandAccountTimelineSuccess(id, response.data, next));
162 }).catch(error => {
163 dispatch(expandAccountTimelineFail(id, error));
164 });
165 };
166 };
167
168 export function expandAccountMediaTimeline(id) {
169 return (dispatch, getState) => {
170 const lastId = getState().getIn(['timelines', 'accounts_media_timelines', id, 'items'], Immutable.List()).last();
171
172 dispatch(expandAccountMediaTimelineRequest(id));
173
174 api(getState).get(`/api/v1/accounts/${id}/statuses`, {
175 params: {
176 limit: 12,
177 only_media: 'true',
178 max_id: lastId,
179 },
180 }).then(response => {
181 const next = getLinks(response).refs.find(link => link.rel === 'next');
182 dispatch(expandAccountMediaTimelineSuccess(id, response.data, next));
183 }).catch(error => {
184 dispatch(expandAccountMediaTimelineFail(id, error));
185 });
186 };
187 };
188
189 export function fetchAccountRequest(id) {
190 return {
191 type: ACCOUNT_FETCH_REQUEST,
192 id,
193 };
194 };
195
196 export function fetchAccountSuccess(account) {
197 return {
198 type: ACCOUNT_FETCH_SUCCESS,
199 account,
200 };
201 };
202
203 export function fetchAccountFail(id, error) {
204 return {
205 type: ACCOUNT_FETCH_FAIL,
206 id,
207 error,
208 skipAlert: true,
209 };
210 };
211
212 export function followAccount(id) {
213 return (dispatch, getState) => {
214 dispatch(followAccountRequest(id));
215
216 api(getState).post(`/api/v1/accounts/${id}/follow`).then(response => {
217 dispatch(followAccountSuccess(response.data));
218 }).catch(error => {
219 dispatch(followAccountFail(error));
220 });
221 };
222 };
223
224 export function unfollowAccount(id) {
225 return (dispatch, getState) => {
226 dispatch(unfollowAccountRequest(id));
227
228 api(getState).post(`/api/v1/accounts/${id}/unfollow`).then(response => {
229 dispatch(unfollowAccountSuccess(response.data));
230 }).catch(error => {
231 dispatch(unfollowAccountFail(error));
232 });
233 };
234 };
235
236 export function followAccountRequest(id) {
237 return {
238 type: ACCOUNT_FOLLOW_REQUEST,
239 id,
240 };
241 };
242
243 export function followAccountSuccess(relationship) {
244 return {
245 type: ACCOUNT_FOLLOW_SUCCESS,
246 relationship,
247 };
248 };
249
250 export function followAccountFail(error) {
251 return {
252 type: ACCOUNT_FOLLOW_FAIL,
253 error,
254 };
255 };
256
257 export function unfollowAccountRequest(id) {
258 return {
259 type: ACCOUNT_UNFOLLOW_REQUEST,
260 id,
261 };
262 };
263
264 export function unfollowAccountSuccess(relationship) {
265 return {
266 type: ACCOUNT_UNFOLLOW_SUCCESS,
267 relationship,
268 };
269 };
270
271 export function unfollowAccountFail(error) {
272 return {
273 type: ACCOUNT_UNFOLLOW_FAIL,
274 error,
275 };
276 };
277
278 export function fetchAccountTimelineRequest(id, skipLoading) {
279 return {
280 type: ACCOUNT_TIMELINE_FETCH_REQUEST,
281 id,
282 skipLoading,
283 };
284 };
285
286 export function fetchAccountTimelineSuccess(id, statuses, replace, skipLoading) {
287 return {
288 type: ACCOUNT_TIMELINE_FETCH_SUCCESS,
289 id,
290 statuses,
291 replace,
292 skipLoading,
293 };
294 };
295
296 export function fetchAccountTimelineFail(id, error, skipLoading) {
297 return {
298 type: ACCOUNT_TIMELINE_FETCH_FAIL,
299 id,
300 error,
301 skipLoading,
302 skipAlert: error.response.status === 404,
303 };
304 };
305
306 export function fetchAccountMediaTimelineRequest(id, skipLoading) {
307 return {
308 type: ACCOUNT_MEDIA_TIMELINE_FETCH_REQUEST,
309 id,
310 skipLoading,
311 };
312 };
313
314 export function fetchAccountMediaTimelineSuccess(id, statuses, replace, skipLoading) {
315 return {
316 type: ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS,
317 id,
318 statuses,
319 replace,
320 skipLoading,
321 };
322 };
323
324 export function fetchAccountMediaTimelineFail(id, error, skipLoading) {
325 return {
326 type: ACCOUNT_MEDIA_TIMELINE_FETCH_FAIL,
327 id,
328 error,
329 skipLoading,
330 skipAlert: error.response.status === 404,
331 };
332 };
333
334 export function expandAccountTimelineRequest(id) {
335 return {
336 type: ACCOUNT_TIMELINE_EXPAND_REQUEST,
337 id,
338 };
339 };
340
341 export function expandAccountTimelineSuccess(id, statuses, next) {
342 return {
343 type: ACCOUNT_TIMELINE_EXPAND_SUCCESS,
344 id,
345 statuses,
346 next,
347 };
348 };
349
350 export function expandAccountTimelineFail(id, error) {
351 return {
352 type: ACCOUNT_TIMELINE_EXPAND_FAIL,
353 id,
354 error,
355 };
356 };
357
358 export function expandAccountMediaTimelineRequest(id) {
359 return {
360 type: ACCOUNT_MEDIA_TIMELINE_EXPAND_REQUEST,
361 id,
362 };
363 };
364
365 export function expandAccountMediaTimelineSuccess(id, statuses, next) {
366 return {
367 type: ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS,
368 id,
369 statuses,
370 next,
371 };
372 };
373
374 export function expandAccountMediaTimelineFail(id, error) {
375 return {
376 type: ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL,
377 id,
378 error,
379 };
380 };
381
382 export function blockAccount(id) {
383 return (dispatch, getState) => {
384 dispatch(blockAccountRequest(id));
385
386 api(getState).post(`/api/v1/accounts/${id}/block`).then(response => {
387 // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers
388 dispatch(blockAccountSuccess(response.data, getState().get('statuses')));
389 }).catch(error => {
390 dispatch(blockAccountFail(id, error));
391 });
392 };
393 };
394
395 export function unblockAccount(id) {
396 return (dispatch, getState) => {
397 dispatch(unblockAccountRequest(id));
398
399 api(getState).post(`/api/v1/accounts/${id}/unblock`).then(response => {
400 dispatch(unblockAccountSuccess(response.data));
401 }).catch(error => {
402 dispatch(unblockAccountFail(id, error));
403 });
404 };
405 };
406
407 export function blockAccountRequest(id) {
408 return {
409 type: ACCOUNT_BLOCK_REQUEST,
410 id,
411 };
412 };
413
414 export function blockAccountSuccess(relationship, statuses) {
415 return {
416 type: ACCOUNT_BLOCK_SUCCESS,
417 relationship,
418 statuses,
419 };
420 };
421
422 export function blockAccountFail(error) {
423 return {
424 type: ACCOUNT_BLOCK_FAIL,
425 error,
426 };
427 };
428
429 export function unblockAccountRequest(id) {
430 return {
431 type: ACCOUNT_UNBLOCK_REQUEST,
432 id,
433 };
434 };
435
436 export function unblockAccountSuccess(relationship) {
437 return {
438 type: ACCOUNT_UNBLOCK_SUCCESS,
439 relationship,
440 };
441 };
442
443 export function unblockAccountFail(error) {
444 return {
445 type: ACCOUNT_UNBLOCK_FAIL,
446 error,
447 };
448 };
449
450
451 export function muteAccount(id) {
452 return (dispatch, getState) => {
453 dispatch(muteAccountRequest(id));
454
455 api(getState).post(`/api/v1/accounts/${id}/mute`).then(response => {
456 // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers
457 dispatch(muteAccountSuccess(response.data, getState().get('statuses')));
458 }).catch(error => {
459 dispatch(muteAccountFail(id, error));
460 });
461 };
462 };
463
464 export function unmuteAccount(id) {
465 return (dispatch, getState) => {
466 dispatch(unmuteAccountRequest(id));
467
468 api(getState).post(`/api/v1/accounts/${id}/unmute`).then(response => {
469 dispatch(unmuteAccountSuccess(response.data));
470 }).catch(error => {
471 dispatch(unmuteAccountFail(id, error));
472 });
473 };
474 };
475
476 export function muteAccountRequest(id) {
477 return {
478 type: ACCOUNT_MUTE_REQUEST,
479 id,
480 };
481 };
482
483 export function muteAccountSuccess(relationship, statuses) {
484 return {
485 type: ACCOUNT_MUTE_SUCCESS,
486 relationship,
487 statuses,
488 };
489 };
490
491 export function muteAccountFail(error) {
492 return {
493 type: ACCOUNT_MUTE_FAIL,
494 error,
495 };
496 };
497
498 export function unmuteAccountRequest(id) {
499 return {
500 type: ACCOUNT_UNMUTE_REQUEST,
501 id,
502 };
503 };
504
505 export function unmuteAccountSuccess(relationship) {
506 return {
507 type: ACCOUNT_UNMUTE_SUCCESS,
508 relationship,
509 };
510 };
511
512 export function unmuteAccountFail(error) {
513 return {
514 type: ACCOUNT_UNMUTE_FAIL,
515 error,
516 };
517 };
518
519
520 export function fetchFollowers(id) {
521 return (dispatch, getState) => {
522 dispatch(fetchFollowersRequest(id));
523
524 api(getState).get(`/api/v1/accounts/${id}/followers`).then(response => {
525 const next = getLinks(response).refs.find(link => link.rel === 'next');
526
527 dispatch(fetchFollowersSuccess(id, response.data, next ? next.uri : null));
528 dispatch(fetchRelationships(response.data.map(item => item.id)));
529 }).catch(error => {
530 dispatch(fetchFollowersFail(id, error));
531 });
532 };
533 };
534
535 export function fetchFollowersRequest(id) {
536 return {
537 type: FOLLOWERS_FETCH_REQUEST,
538 id,
539 };
540 };
541
542 export function fetchFollowersSuccess(id, accounts, next) {
543 return {
544 type: FOLLOWERS_FETCH_SUCCESS,
545 id,
546 accounts,
547 next,
548 };
549 };
550
551 export function fetchFollowersFail(id, error) {
552 return {
553 type: FOLLOWERS_FETCH_FAIL,
554 id,
555 error,
556 };
557 };
558
559 export function expandFollowers(id) {
560 return (dispatch, getState) => {
561 const url = getState().getIn(['user_lists', 'followers', id, 'next']);
562
563 if (url === null) {
564 return;
565 }
566
567 dispatch(expandFollowersRequest(id));
568
569 api(getState).get(url).then(response => {
570 const next = getLinks(response).refs.find(link => link.rel === 'next');
571
572 dispatch(expandFollowersSuccess(id, response.data, next ? next.uri : null));
573 dispatch(fetchRelationships(response.data.map(item => item.id)));
574 }).catch(error => {
575 dispatch(expandFollowersFail(id, error));
576 });
577 };
578 };
579
580 export function expandFollowersRequest(id) {
581 return {
582 type: FOLLOWERS_EXPAND_REQUEST,
583 id,
584 };
585 };
586
587 export function expandFollowersSuccess(id, accounts, next) {
588 return {
589 type: FOLLOWERS_EXPAND_SUCCESS,
590 id,
591 accounts,
592 next,
593 };
594 };
595
596 export function expandFollowersFail(id, error) {
597 return {
598 type: FOLLOWERS_EXPAND_FAIL,
599 id,
600 error,
601 };
602 };
603
604 export function fetchFollowing(id) {
605 return (dispatch, getState) => {
606 dispatch(fetchFollowingRequest(id));
607
608 api(getState).get(`/api/v1/accounts/${id}/following`).then(response => {
609 const next = getLinks(response).refs.find(link => link.rel === 'next');
610
611 dispatch(fetchFollowingSuccess(id, response.data, next ? next.uri : null));
612 dispatch(fetchRelationships(response.data.map(item => item.id)));
613 }).catch(error => {
614 dispatch(fetchFollowingFail(id, error));
615 });
616 };
617 };
618
619 export function fetchFollowingRequest(id) {
620 return {
621 type: FOLLOWING_FETCH_REQUEST,
622 id,
623 };
624 };
625
626 export function fetchFollowingSuccess(id, accounts, next) {
627 return {
628 type: FOLLOWING_FETCH_SUCCESS,
629 id,
630 accounts,
631 next,
632 };
633 };
634
635 export function fetchFollowingFail(id, error) {
636 return {
637 type: FOLLOWING_FETCH_FAIL,
638 id,
639 error,
640 };
641 };
642
643 export function expandFollowing(id) {
644 return (dispatch, getState) => {
645 const url = getState().getIn(['user_lists', 'following', id, 'next']);
646
647 if (url === null) {
648 return;
649 }
650
651 dispatch(expandFollowingRequest(id));
652
653 api(getState).get(url).then(response => {
654 const next = getLinks(response).refs.find(link => link.rel === 'next');
655
656 dispatch(expandFollowingSuccess(id, response.data, next ? next.uri : null));
657 dispatch(fetchRelationships(response.data.map(item => item.id)));
658 }).catch(error => {
659 dispatch(expandFollowingFail(id, error));
660 });
661 };
662 };
663
664 export function expandFollowingRequest(id) {
665 return {
666 type: FOLLOWING_EXPAND_REQUEST,
667 id,
668 };
669 };
670
671 export function expandFollowingSuccess(id, accounts, next) {
672 return {
673 type: FOLLOWING_EXPAND_SUCCESS,
674 id,
675 accounts,
676 next,
677 };
678 };
679
680 export function expandFollowingFail(id, error) {
681 return {
682 type: FOLLOWING_EXPAND_FAIL,
683 id,
684 error,
685 };
686 };
687
688 export function fetchRelationships(accountIds) {
689 return (dispatch, getState) => {
690 const loadedRelationships = getState().get('relationships');
691 const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null);
692
693 if (newAccountIds.length === 0) {
694 return;
695 }
696
697 dispatch(fetchRelationshipsRequest(newAccountIds));
698
699 api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
700 dispatch(fetchRelationshipsSuccess(response.data));
701 }).catch(error => {
702 dispatch(fetchRelationshipsFail(error));
703 });
704 };
705 };
706
707 export function fetchRelationshipsRequest(ids) {
708 return {
709 type: RELATIONSHIPS_FETCH_REQUEST,
710 ids,
711 skipLoading: true,
712 };
713 };
714
715 export function fetchRelationshipsSuccess(relationships) {
716 return {
717 type: RELATIONSHIPS_FETCH_SUCCESS,
718 relationships,
719 skipLoading: true,
720 };
721 };
722
723 export function fetchRelationshipsFail(error) {
724 return {
725 type: RELATIONSHIPS_FETCH_FAIL,
726 error,
727 skipLoading: true,
728 };
729 };
730
731 export function fetchFollowRequests() {
732 return (dispatch, getState) => {
733 dispatch(fetchFollowRequestsRequest());
734
735 api(getState).get('/api/v1/follow_requests').then(response => {
736 const next = getLinks(response).refs.find(link => link.rel === 'next');
737 dispatch(fetchFollowRequestsSuccess(response.data, next ? next.uri : null));
738 }).catch(error => dispatch(fetchFollowRequestsFail(error)));
739 };
740 };
741
742 export function fetchFollowRequestsRequest() {
743 return {
744 type: FOLLOW_REQUESTS_FETCH_REQUEST,
745 };
746 };
747
748 export function fetchFollowRequestsSuccess(accounts, next) {
749 return {
750 type: FOLLOW_REQUESTS_FETCH_SUCCESS,
751 accounts,
752 next,
753 };
754 };
755
756 export function fetchFollowRequestsFail(error) {
757 return {
758 type: FOLLOW_REQUESTS_FETCH_FAIL,
759 error,
760 };
761 };
762
763 export function expandFollowRequests() {
764 return (dispatch, getState) => {
765 const url = getState().getIn(['user_lists', 'follow_requests', 'next']);
766
767 if (url === null) {
768 return;
769 }
770
771 dispatch(expandFollowRequestsRequest());
772
773 api(getState).get(url).then(response => {
774 const next = getLinks(response).refs.find(link => link.rel === 'next');
775 dispatch(expandFollowRequestsSuccess(response.data, next ? next.uri : null));
776 }).catch(error => dispatch(expandFollowRequestsFail(error)));
777 };
778 };
779
780 export function expandFollowRequestsRequest() {
781 return {
782 type: FOLLOW_REQUESTS_EXPAND_REQUEST,
783 };
784 };
785
786 export function expandFollowRequestsSuccess(accounts, next) {
787 return {
788 type: FOLLOW_REQUESTS_EXPAND_SUCCESS,
789 accounts,
790 next,
791 };
792 };
793
794 export function expandFollowRequestsFail(error) {
795 return {
796 type: FOLLOW_REQUESTS_EXPAND_FAIL,
797 error,
798 };
799 };
800
801 export function authorizeFollowRequest(id) {
802 return (dispatch, getState) => {
803 dispatch(authorizeFollowRequestRequest(id));
804
805 api(getState)
806 .post(`/api/v1/follow_requests/${id}/authorize`)
807 .then(response => dispatch(authorizeFollowRequestSuccess(id)))
808 .catch(error => dispatch(authorizeFollowRequestFail(id, error)));
809 };
810 };
811
812 export function authorizeFollowRequestRequest(id) {
813 return {
814 type: FOLLOW_REQUEST_AUTHORIZE_REQUEST,
815 id,
816 };
817 };
818
819 export function authorizeFollowRequestSuccess(id) {
820 return {
821 type: FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
822 id,
823 };
824 };
825
826 export function authorizeFollowRequestFail(id, error) {
827 return {
828 type: FOLLOW_REQUEST_AUTHORIZE_FAIL,
829 id,
830 error,
831 };
832 };
833
834
835 export function rejectFollowRequest(id) {
836 return (dispatch, getState) => {
837 dispatch(rejectFollowRequestRequest(id));
838
839 api(getState)
840 .post(`/api/v1/follow_requests/${id}/reject`)
841 .then(response => dispatch(rejectFollowRequestSuccess(id)))
842 .catch(error => dispatch(rejectFollowRequestFail(id, error)));
843 };
844 };
845
846 export function rejectFollowRequestRequest(id) {
847 return {
848 type: FOLLOW_REQUEST_REJECT_REQUEST,
849 id,
850 };
851 };
852
853 export function rejectFollowRequestSuccess(id) {
854 return {
855 type: FOLLOW_REQUEST_REJECT_SUCCESS,
856 id,
857 };
858 };
859
860 export function rejectFollowRequestFail(id, error) {
861 return {
862 type: FOLLOW_REQUEST_REJECT_FAIL,
863 id,
864 error,
865 };
866 };
This page took 0.245429 seconds and 4 git commands to generate.