1 import api
, { getLinks
} from 'flavours/glitch/util/api';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
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';
83 export const PINNED_ACCOUNTS_EDITOR_RESET
= 'PINNED_ACCOUNTS_EDITOR_RESET';
86 export function fetchAccount(id
) {
87 return (dispatch
, getState
) => {
88 dispatch(fetchRelationships([id
]));
90 if (getState().getIn(['accounts', id
], null) !== null) {
94 dispatch(fetchAccountRequest(id
));
96 api(getState
).get(`/api/v1/accounts/${id}`).then(response
=> {
97 dispatch(fetchAccountSuccess(response
.data
));
99 dispatch(fetchAccountFail(id
, error
));
104 export function fetchAccountRequest(id
) {
106 type: ACCOUNT_FETCH_REQUEST
,
111 export function fetchAccountSuccess(account
) {
113 type: ACCOUNT_FETCH_SUCCESS
,
118 export function fetchAccountFail(id
, error
) {
120 type: ACCOUNT_FETCH_FAIL
,
127 export function followAccount(id
, reblogs
= true) {
128 return (dispatch
, getState
) => {
129 const alreadyFollowing
= getState().getIn(['relationships', id
, 'following']);
130 dispatch(followAccountRequest(id
));
132 api(getState
).post(`/api/v1/accounts/${id}/follow`, { reblogs
}).then(response
=> {
133 dispatch(followAccountSuccess(response
.data
, alreadyFollowing
));
135 dispatch(followAccountFail(error
));
140 export function unfollowAccount(id
) {
141 return (dispatch
, getState
) => {
142 dispatch(unfollowAccountRequest(id
));
144 api(getState
).post(`/api/v1/accounts/${id}/unfollow`).then(response
=> {
145 dispatch(unfollowAccountSuccess(response
.data
, getState().get('statuses')));
147 dispatch(unfollowAccountFail(error
));
152 export function followAccountRequest(id
) {
154 type: ACCOUNT_FOLLOW_REQUEST
,
159 export function followAccountSuccess(relationship
, alreadyFollowing
) {
161 type: ACCOUNT_FOLLOW_SUCCESS
,
167 export function followAccountFail(error
) {
169 type: ACCOUNT_FOLLOW_FAIL
,
174 export function unfollowAccountRequest(id
) {
176 type: ACCOUNT_UNFOLLOW_REQUEST
,
181 export function unfollowAccountSuccess(relationship
, statuses
) {
183 type: ACCOUNT_UNFOLLOW_SUCCESS
,
189 export function unfollowAccountFail(error
) {
191 type: ACCOUNT_UNFOLLOW_FAIL
,
196 export function blockAccount(id
) {
197 return (dispatch
, getState
) => {
198 dispatch(blockAccountRequest(id
));
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')));
204 dispatch(blockAccountFail(id
, error
));
209 export function unblockAccount(id
) {
210 return (dispatch
, getState
) => {
211 dispatch(unblockAccountRequest(id
));
213 api(getState
).post(`/api/v1/accounts/${id}/unblock`).then(response
=> {
214 dispatch(unblockAccountSuccess(response
.data
));
216 dispatch(unblockAccountFail(id
, error
));
221 export function blockAccountRequest(id
) {
223 type: ACCOUNT_BLOCK_REQUEST
,
228 export function blockAccountSuccess(relationship
, statuses
) {
230 type: ACCOUNT_BLOCK_SUCCESS
,
236 export function blockAccountFail(error
) {
238 type: ACCOUNT_BLOCK_FAIL
,
243 export function unblockAccountRequest(id
) {
245 type: ACCOUNT_UNBLOCK_REQUEST
,
250 export function unblockAccountSuccess(relationship
) {
252 type: ACCOUNT_UNBLOCK_SUCCESS
,
257 export function unblockAccountFail(error
) {
259 type: ACCOUNT_UNBLOCK_FAIL
,
265 export function muteAccount(id
, notifications
) {
266 return (dispatch
, getState
) => {
267 dispatch(muteAccountRequest(id
));
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')));
273 dispatch(muteAccountFail(id
, error
));
278 export function unmuteAccount(id
) {
279 return (dispatch
, getState
) => {
280 dispatch(unmuteAccountRequest(id
));
282 api(getState
).post(`/api/v1/accounts/${id}/unmute`).then(response
=> {
283 dispatch(unmuteAccountSuccess(response
.data
));
285 dispatch(unmuteAccountFail(id
, error
));
290 export function muteAccountRequest(id
) {
292 type: ACCOUNT_MUTE_REQUEST
,
297 export function muteAccountSuccess(relationship
, statuses
) {
299 type: ACCOUNT_MUTE_SUCCESS
,
305 export function muteAccountFail(error
) {
307 type: ACCOUNT_MUTE_FAIL
,
312 export function unmuteAccountRequest(id
) {
314 type: ACCOUNT_UNMUTE_REQUEST
,
319 export function unmuteAccountSuccess(relationship
) {
321 type: ACCOUNT_UNMUTE_SUCCESS
,
326 export function unmuteAccountFail(error
) {
328 type: ACCOUNT_UNMUTE_FAIL
,
334 export function fetchFollowers(id
) {
335 return (dispatch
, getState
) => {
336 dispatch(fetchFollowersRequest(id
));
338 api(getState
).get(`/api/v1/accounts/${id}/followers`).then(response
=> {
339 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
341 dispatch(fetchFollowersSuccess(id
, response
.data
, next
? next
.uri : null));
342 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
344 dispatch(fetchFollowersFail(id
, error
));
349 export function fetchFollowersRequest(id
) {
351 type: FOLLOWERS_FETCH_REQUEST
,
356 export function fetchFollowersSuccess(id
, accounts
, next
) {
358 type: FOLLOWERS_FETCH_SUCCESS
,
365 export function fetchFollowersFail(id
, error
) {
367 type: FOLLOWERS_FETCH_FAIL
,
373 export function expandFollowers(id
) {
374 return (dispatch
, getState
) => {
375 const url
= getState().getIn(['user_lists', 'followers', id
, 'next']);
381 dispatch(expandFollowersRequest(id
));
383 api(getState
).get(url
).then(response
=> {
384 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
386 dispatch(expandFollowersSuccess(id
, response
.data
, next
? next
.uri : null));
387 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
389 dispatch(expandFollowersFail(id
, error
));
394 export function expandFollowersRequest(id
) {
396 type: FOLLOWERS_EXPAND_REQUEST
,
401 export function expandFollowersSuccess(id
, accounts
, next
) {
403 type: FOLLOWERS_EXPAND_SUCCESS
,
410 export function expandFollowersFail(id
, error
) {
412 type: FOLLOWERS_EXPAND_FAIL
,
418 export function fetchFollowing(id
) {
419 return (dispatch
, getState
) => {
420 dispatch(fetchFollowingRequest(id
));
422 api(getState
).get(`/api/v1/accounts/${id}/following`).then(response
=> {
423 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
425 dispatch(fetchFollowingSuccess(id
, response
.data
, next
? next
.uri : null));
426 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
428 dispatch(fetchFollowingFail(id
, error
));
433 export function fetchFollowingRequest(id
) {
435 type: FOLLOWING_FETCH_REQUEST
,
440 export function fetchFollowingSuccess(id
, accounts
, next
) {
442 type: FOLLOWING_FETCH_SUCCESS
,
449 export function fetchFollowingFail(id
, error
) {
451 type: FOLLOWING_FETCH_FAIL
,
457 export function expandFollowing(id
) {
458 return (dispatch
, getState
) => {
459 const url
= getState().getIn(['user_lists', 'following', id
, 'next']);
465 dispatch(expandFollowingRequest(id
));
467 api(getState
).get(url
).then(response
=> {
468 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
470 dispatch(expandFollowingSuccess(id
, response
.data
, next
? next
.uri : null));
471 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
473 dispatch(expandFollowingFail(id
, error
));
478 export function expandFollowingRequest(id
) {
480 type: FOLLOWING_EXPAND_REQUEST
,
485 export function expandFollowingSuccess(id
, accounts
, next
) {
487 type: FOLLOWING_EXPAND_SUCCESS
,
494 export function expandFollowingFail(id
, error
) {
496 type: FOLLOWING_EXPAND_FAIL
,
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);
507 if (newAccountIds
.length
=== 0) {
511 dispatch(fetchRelationshipsRequest(newAccountIds
));
513 api(getState
).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
514 dispatch(fetchRelationshipsSuccess(response.data));
516 dispatch(fetchRelationshipsFail(error));
521 export function fetchRelationshipsRequest(ids) {
523 type: RELATIONSHIPS_FETCH_REQUEST,
529 export function fetchRelationshipsSuccess(relationships) {
531 type: RELATIONSHIPS_FETCH_SUCCESS,
537 export function fetchRelationshipsFail(error) {
539 type: RELATIONSHIPS_FETCH_FAIL,
545 export function fetchFollowRequests() {
546 return (dispatch, getState) => {
547 dispatch(fetchFollowRequestsRequest());
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)));
556 export function fetchFollowRequestsRequest() {
558 type: FOLLOW_REQUESTS_FETCH_REQUEST,
562 export function fetchFollowRequestsSuccess(accounts, next) {
564 type: FOLLOW_REQUESTS_FETCH_SUCCESS,
570 export function fetchFollowRequestsFail(error) {
572 type: FOLLOW_REQUESTS_FETCH_FAIL,
577 export function expandFollowRequests() {
578 return (dispatch, getState) => {
579 const url = getState().getIn(['user_lists', 'follow_requests', 'next']);
585 dispatch(expandFollowRequestsRequest());
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)));
594 export function expandFollowRequestsRequest() {
596 type: FOLLOW_REQUESTS_EXPAND_REQUEST,
600 export function expandFollowRequestsSuccess(accounts, next) {
602 type: FOLLOW_REQUESTS_EXPAND_SUCCESS,
608 export function expandFollowRequestsFail(error) {
610 type: FOLLOW_REQUESTS_EXPAND_FAIL,
615 export function authorizeFollowRequest(id) {
616 return (dispatch, getState) => {
617 dispatch(authorizeFollowRequestRequest(id));
620 .post(`/api/v1
/follow_requests/${id}
/authorize
`)
621 .then(() => dispatch(authorizeFollowRequestSuccess(id)))
622 .catch(error => dispatch(authorizeFollowRequestFail(id, error)));
626 export function authorizeFollowRequestRequest(id) {
628 type: FOLLOW_REQUEST_AUTHORIZE_REQUEST,
633 export function authorizeFollowRequestSuccess(id) {
635 type: FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
640 export function authorizeFollowRequestFail(id, error) {
642 type: FOLLOW_REQUEST_AUTHORIZE_FAIL,
649 export function rejectFollowRequest(id) {
650 return (dispatch, getState) => {
651 dispatch(rejectFollowRequestRequest(id));
654 .post(`/api/v1
/follow_requests/${id}
/reject
`)
655 .then(() => dispatch(rejectFollowRequestSuccess(id)))
656 .catch(error => dispatch(rejectFollowRequestFail(id, error)));
660 export function rejectFollowRequestRequest(id) {
662 type: FOLLOW_REQUEST_REJECT_REQUEST,
667 export function rejectFollowRequestSuccess(id) {
669 type: FOLLOW_REQUEST_REJECT_SUCCESS,
674 export function rejectFollowRequestFail(id, error) {
676 type: FOLLOW_REQUEST_REJECT_FAIL,
682 export function pinAccount(id) {
683 return (dispatch, getState) => {
684 dispatch(pinAccountRequest(id));
686 api(getState).post(`/api/v1
/accounts/${id}
/pin
`).then(response => {
687 dispatch(pinAccountSuccess(response.data));
689 dispatch(pinAccountFail(error));
694 export function unpinAccount(id) {
695 return (dispatch, getState) => {
696 dispatch(unpinAccountRequest(id));
698 api(getState).post(`/api/v1
/accounts/${id}
/unpin
`).then(response => {
699 dispatch(unpinAccountSuccess(response.data));
701 dispatch(unpinAccountFail(error));
706 export function pinAccountRequest(id) {
708 type: ACCOUNT_PIN_REQUEST,
713 export function pinAccountSuccess(relationship) {
715 type: ACCOUNT_PIN_SUCCESS,
720 export function pinAccountFail(error) {
722 type: ACCOUNT_PIN_FAIL,
727 export function unpinAccountRequest(id) {
729 type: ACCOUNT_UNPIN_REQUEST,
734 export function unpinAccountSuccess(relationship) {
736 type: ACCOUNT_UNPIN_SUCCESS,
741 export function unpinAccountFail(error) {
743 type: ACCOUNT_UNPIN_FAIL,
748 export function fetchPinnedAccounts() {
749 return (dispatch, getState) => {
750 dispatch(fetchPinnedAccountsRequest());
752 api(getState).get(`/api/v1
/endorsements
`, { params: { limit: 0 } })
753 .then(({ data }) => dispatch(fetchPinnedAccountsSuccess(data)))
754 .catch(err => dispatch(fetchPinnedAccountsFail(err)));
758 export function fetchPinnedAccountsRequest() {
760 type: PINNED_ACCOUNTS_FETCH_REQUEST,
764 export function fetchPinnedAccountsSuccess(accounts, next) {
766 type: PINNED_ACCOUNTS_FETCH_SUCCESS,
772 export function fetchPinnedAccountsFail(error) {
774 type: PINNED_ACCOUNTS_FETCH_FAIL,
779 export function fetchPinnedAccountsSuggestions(q) {
780 return (dispatch, getState) => {
788 api(getState).get('/api/v1/accounts/search', { params })
789 .then(({ data }) => dispatch(fetchPinnedAccountsSuggestionsReady(q, data)));
793 export function fetchPinnedAccountsSuggestionsReady(query, accounts) {
795 type: PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_READY,
801 export function clearPinnedAccountsSuggestions() {
803 type: PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CLEAR,
807 export function changePinnedAccountsSuggestions(value) {
809 type: PINNED_ACCOUNTS_EDITOR_SUGGESTIONS_CHANGE,
814 export function resetPinnedAccountsEditor() {
816 type: PINNED_ACCOUNTS_EDITOR_RESET,