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