1 import api
, { getLinks
} from '../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 FOLLOWERS_FETCH_REQUEST
= 'FOLLOWERS_FETCH_REQUEST';
32 export const FOLLOWERS_FETCH_SUCCESS
= 'FOLLOWERS_FETCH_SUCCESS';
33 export const FOLLOWERS_FETCH_FAIL
= 'FOLLOWERS_FETCH_FAIL';
35 export const FOLLOWERS_EXPAND_REQUEST
= 'FOLLOWERS_EXPAND_REQUEST';
36 export const FOLLOWERS_EXPAND_SUCCESS
= 'FOLLOWERS_EXPAND_SUCCESS';
37 export const FOLLOWERS_EXPAND_FAIL
= 'FOLLOWERS_EXPAND_FAIL';
39 export const FOLLOWING_FETCH_REQUEST
= 'FOLLOWING_FETCH_REQUEST';
40 export const FOLLOWING_FETCH_SUCCESS
= 'FOLLOWING_FETCH_SUCCESS';
41 export const FOLLOWING_FETCH_FAIL
= 'FOLLOWING_FETCH_FAIL';
43 export const FOLLOWING_EXPAND_REQUEST
= 'FOLLOWING_EXPAND_REQUEST';
44 export const FOLLOWING_EXPAND_SUCCESS
= 'FOLLOWING_EXPAND_SUCCESS';
45 export const FOLLOWING_EXPAND_FAIL
= 'FOLLOWING_EXPAND_FAIL';
47 export const RELATIONSHIPS_FETCH_REQUEST
= 'RELATIONSHIPS_FETCH_REQUEST';
48 export const RELATIONSHIPS_FETCH_SUCCESS
= 'RELATIONSHIPS_FETCH_SUCCESS';
49 export const RELATIONSHIPS_FETCH_FAIL
= 'RELATIONSHIPS_FETCH_FAIL';
51 export const FOLLOW_REQUESTS_FETCH_REQUEST
= 'FOLLOW_REQUESTS_FETCH_REQUEST';
52 export const FOLLOW_REQUESTS_FETCH_SUCCESS
= 'FOLLOW_REQUESTS_FETCH_SUCCESS';
53 export const FOLLOW_REQUESTS_FETCH_FAIL
= 'FOLLOW_REQUESTS_FETCH_FAIL';
55 export const FOLLOW_REQUESTS_EXPAND_REQUEST
= 'FOLLOW_REQUESTS_EXPAND_REQUEST';
56 export const FOLLOW_REQUESTS_EXPAND_SUCCESS
= 'FOLLOW_REQUESTS_EXPAND_SUCCESS';
57 export const FOLLOW_REQUESTS_EXPAND_FAIL
= 'FOLLOW_REQUESTS_EXPAND_FAIL';
59 export const FOLLOW_REQUEST_AUTHORIZE_REQUEST
= 'FOLLOW_REQUEST_AUTHORIZE_REQUEST';
60 export const FOLLOW_REQUEST_AUTHORIZE_SUCCESS
= 'FOLLOW_REQUEST_AUTHORIZE_SUCCESS';
61 export const FOLLOW_REQUEST_AUTHORIZE_FAIL
= 'FOLLOW_REQUEST_AUTHORIZE_FAIL';
63 export const FOLLOW_REQUEST_REJECT_REQUEST
= 'FOLLOW_REQUEST_REJECT_REQUEST';
64 export const FOLLOW_REQUEST_REJECT_SUCCESS
= 'FOLLOW_REQUEST_REJECT_SUCCESS';
65 export const FOLLOW_REQUEST_REJECT_FAIL
= 'FOLLOW_REQUEST_REJECT_FAIL';
67 export function fetchAccount(id
) {
68 return (dispatch
, getState
) => {
69 dispatch(fetchRelationships([id
]));
71 if (getState().getIn(['accounts', id
], null) !== null) {
75 dispatch(fetchAccountRequest(id
));
77 api(getState
).get(`/api/v1/accounts/${id}`).then(response
=> {
78 dispatch(fetchAccountSuccess(response
.data
));
80 dispatch(fetchAccountFail(id
, error
));
85 export function fetchAccountRequest(id
) {
87 type: ACCOUNT_FETCH_REQUEST
,
92 export function fetchAccountSuccess(account
) {
94 type: ACCOUNT_FETCH_SUCCESS
,
99 export function fetchAccountFail(id
, error
) {
101 type: ACCOUNT_FETCH_FAIL
,
108 export function followAccount(id
) {
109 return (dispatch
, getState
) => {
110 dispatch(followAccountRequest(id
));
112 api(getState
).post(`/api/v1/accounts/${id}/follow`).then(response
=> {
113 dispatch(followAccountSuccess(response
.data
));
115 dispatch(followAccountFail(error
));
120 export function unfollowAccount(id
) {
121 return (dispatch
, getState
) => {
122 dispatch(unfollowAccountRequest(id
));
124 api(getState
).post(`/api/v1/accounts/${id}/unfollow`).then(response
=> {
125 dispatch(unfollowAccountSuccess(response
.data
, getState().get('statuses')));
127 dispatch(unfollowAccountFail(error
));
132 export function followAccountRequest(id
) {
134 type: ACCOUNT_FOLLOW_REQUEST
,
139 export function followAccountSuccess(relationship
) {
141 type: ACCOUNT_FOLLOW_SUCCESS
,
146 export function followAccountFail(error
) {
148 type: ACCOUNT_FOLLOW_FAIL
,
153 export function unfollowAccountRequest(id
) {
155 type: ACCOUNT_UNFOLLOW_REQUEST
,
160 export function unfollowAccountSuccess(relationship
, statuses
) {
162 type: ACCOUNT_UNFOLLOW_SUCCESS
,
168 export function unfollowAccountFail(error
) {
170 type: ACCOUNT_UNFOLLOW_FAIL
,
175 export function blockAccount(id
) {
176 return (dispatch
, getState
) => {
177 dispatch(blockAccountRequest(id
));
179 api(getState
).post(`/api/v1/accounts/${id}/block`).then(response
=> {
180 // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers
181 dispatch(blockAccountSuccess(response
.data
, getState().get('statuses')));
183 dispatch(blockAccountFail(id
, error
));
188 export function unblockAccount(id
) {
189 return (dispatch
, getState
) => {
190 dispatch(unblockAccountRequest(id
));
192 api(getState
).post(`/api/v1/accounts/${id}/unblock`).then(response
=> {
193 dispatch(unblockAccountSuccess(response
.data
));
195 dispatch(unblockAccountFail(id
, error
));
200 export function blockAccountRequest(id
) {
202 type: ACCOUNT_BLOCK_REQUEST
,
207 export function blockAccountSuccess(relationship
, statuses
) {
209 type: ACCOUNT_BLOCK_SUCCESS
,
215 export function blockAccountFail(error
) {
217 type: ACCOUNT_BLOCK_FAIL
,
222 export function unblockAccountRequest(id
) {
224 type: ACCOUNT_UNBLOCK_REQUEST
,
229 export function unblockAccountSuccess(relationship
) {
231 type: ACCOUNT_UNBLOCK_SUCCESS
,
236 export function unblockAccountFail(error
) {
238 type: ACCOUNT_UNBLOCK_FAIL
,
244 export function muteAccount(id
, notifications
) {
245 return (dispatch
, getState
) => {
246 dispatch(muteAccountRequest(id
));
248 api(getState
).post(`/api/v1/accounts/${id}/mute`, { notifications
}).then(response
=> {
249 // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers
250 dispatch(muteAccountSuccess(response
.data
, getState().get('statuses')));
252 dispatch(muteAccountFail(id
, error
));
257 export function unmuteAccount(id
) {
258 return (dispatch
, getState
) => {
259 dispatch(unmuteAccountRequest(id
));
261 api(getState
).post(`/api/v1/accounts/${id}/unmute`).then(response
=> {
262 dispatch(unmuteAccountSuccess(response
.data
));
264 dispatch(unmuteAccountFail(id
, error
));
269 export function muteAccountRequest(id
) {
271 type: ACCOUNT_MUTE_REQUEST
,
276 export function muteAccountSuccess(relationship
, statuses
) {
278 type: ACCOUNT_MUTE_SUCCESS
,
284 export function muteAccountFail(error
) {
286 type: ACCOUNT_MUTE_FAIL
,
291 export function unmuteAccountRequest(id
) {
293 type: ACCOUNT_UNMUTE_REQUEST
,
298 export function unmuteAccountSuccess(relationship
) {
300 type: ACCOUNT_UNMUTE_SUCCESS
,
305 export function unmuteAccountFail(error
) {
307 type: ACCOUNT_UNMUTE_FAIL
,
313 export function fetchFollowers(id
) {
314 return (dispatch
, getState
) => {
315 dispatch(fetchFollowersRequest(id
));
317 api(getState
).get(`/api/v1/accounts/${id}/followers`).then(response
=> {
318 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
320 dispatch(fetchFollowersSuccess(id
, response
.data
, next
? next
.uri : null));
321 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
323 dispatch(fetchFollowersFail(id
, error
));
328 export function fetchFollowersRequest(id
) {
330 type: FOLLOWERS_FETCH_REQUEST
,
335 export function fetchFollowersSuccess(id
, accounts
, next
) {
337 type: FOLLOWERS_FETCH_SUCCESS
,
344 export function fetchFollowersFail(id
, error
) {
346 type: FOLLOWERS_FETCH_FAIL
,
352 export function expandFollowers(id
) {
353 return (dispatch
, getState
) => {
354 const url
= getState().getIn(['user_lists', 'followers', id
, 'next']);
360 dispatch(expandFollowersRequest(id
));
362 api(getState
).get(url
).then(response
=> {
363 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
365 dispatch(expandFollowersSuccess(id
, response
.data
, next
? next
.uri : null));
366 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
368 dispatch(expandFollowersFail(id
, error
));
373 export function expandFollowersRequest(id
) {
375 type: FOLLOWERS_EXPAND_REQUEST
,
380 export function expandFollowersSuccess(id
, accounts
, next
) {
382 type: FOLLOWERS_EXPAND_SUCCESS
,
389 export function expandFollowersFail(id
, error
) {
391 type: FOLLOWERS_EXPAND_FAIL
,
397 export function fetchFollowing(id
) {
398 return (dispatch
, getState
) => {
399 dispatch(fetchFollowingRequest(id
));
401 api(getState
).get(`/api/v1/accounts/${id}/following`).then(response
=> {
402 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
404 dispatch(fetchFollowingSuccess(id
, response
.data
, next
? next
.uri : null));
405 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
407 dispatch(fetchFollowingFail(id
, error
));
412 export function fetchFollowingRequest(id
) {
414 type: FOLLOWING_FETCH_REQUEST
,
419 export function fetchFollowingSuccess(id
, accounts
, next
) {
421 type: FOLLOWING_FETCH_SUCCESS
,
428 export function fetchFollowingFail(id
, error
) {
430 type: FOLLOWING_FETCH_FAIL
,
436 export function expandFollowing(id
) {
437 return (dispatch
, getState
) => {
438 const url
= getState().getIn(['user_lists', 'following', id
, 'next']);
444 dispatch(expandFollowingRequest(id
));
446 api(getState
).get(url
).then(response
=> {
447 const next
= getLinks(response
).refs
.find(link
=> link
.rel
=== 'next');
449 dispatch(expandFollowingSuccess(id
, response
.data
, next
? next
.uri : null));
450 dispatch(fetchRelationships(response
.data
.map(item
=> item
.id
)));
452 dispatch(expandFollowingFail(id
, error
));
457 export function expandFollowingRequest(id
) {
459 type: FOLLOWING_EXPAND_REQUEST
,
464 export function expandFollowingSuccess(id
, accounts
, next
) {
466 type: FOLLOWING_EXPAND_SUCCESS
,
473 export function expandFollowingFail(id
, error
) {
475 type: FOLLOWING_EXPAND_FAIL
,
481 export function fetchRelationships(accountIds
) {
482 return (dispatch
, getState
) => {
483 const loadedRelationships
= getState().get('relationships');
484 const newAccountIds
= accountIds
.filter(id
=> loadedRelationships
.get(id
, null) === null);
486 if (newAccountIds
.length
=== 0) {
490 dispatch(fetchRelationshipsRequest(newAccountIds
));
492 api(getState
).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
493 dispatch(fetchRelationshipsSuccess(response.data));
495 dispatch(fetchRelationshipsFail(error));
500 export function fetchRelationshipsRequest(ids) {
502 type: RELATIONSHIPS_FETCH_REQUEST,
508 export function fetchRelationshipsSuccess(relationships) {
510 type: RELATIONSHIPS_FETCH_SUCCESS,
516 export function fetchRelationshipsFail(error) {
518 type: RELATIONSHIPS_FETCH_FAIL,
524 export function fetchFollowRequests() {
525 return (dispatch, getState) => {
526 dispatch(fetchFollowRequestsRequest());
528 api(getState).get('/api/v1/follow_requests').then(response => {
529 const next = getLinks(response).refs.find(link => link.rel === 'next');
530 dispatch(fetchFollowRequestsSuccess(response.data, next ? next.uri : null));
531 }).catch(error => dispatch(fetchFollowRequestsFail(error)));
535 export function fetchFollowRequestsRequest() {
537 type: FOLLOW_REQUESTS_FETCH_REQUEST,
541 export function fetchFollowRequestsSuccess(accounts, next) {
543 type: FOLLOW_REQUESTS_FETCH_SUCCESS,
549 export function fetchFollowRequestsFail(error) {
551 type: FOLLOW_REQUESTS_FETCH_FAIL,
556 export function expandFollowRequests() {
557 return (dispatch, getState) => {
558 const url = getState().getIn(['user_lists', 'follow_requests', 'next']);
564 dispatch(expandFollowRequestsRequest());
566 api(getState).get(url).then(response => {
567 const next = getLinks(response).refs.find(link => link.rel === 'next');
568 dispatch(expandFollowRequestsSuccess(response.data, next ? next.uri : null));
569 }).catch(error => dispatch(expandFollowRequestsFail(error)));
573 export function expandFollowRequestsRequest() {
575 type: FOLLOW_REQUESTS_EXPAND_REQUEST,
579 export function expandFollowRequestsSuccess(accounts, next) {
581 type: FOLLOW_REQUESTS_EXPAND_SUCCESS,
587 export function expandFollowRequestsFail(error) {
589 type: FOLLOW_REQUESTS_EXPAND_FAIL,
594 export function authorizeFollowRequest(id) {
595 return (dispatch, getState) => {
596 dispatch(authorizeFollowRequestRequest(id));
599 .post(`/api/v1
/follow_requests/${id}
/authorize
`)
600 .then(() => dispatch(authorizeFollowRequestSuccess(id)))
601 .catch(error => dispatch(authorizeFollowRequestFail(id, error)));
605 export function authorizeFollowRequestRequest(id) {
607 type: FOLLOW_REQUEST_AUTHORIZE_REQUEST,
612 export function authorizeFollowRequestSuccess(id) {
614 type: FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
619 export function authorizeFollowRequestFail(id, error) {
621 type: FOLLOW_REQUEST_AUTHORIZE_FAIL,
628 export function rejectFollowRequest(id) {
629 return (dispatch, getState) => {
630 dispatch(rejectFollowRequestRequest(id));
633 .post(`/api/v1
/follow_requests/${id}
/reject
`)
634 .then(() => dispatch(rejectFollowRequestSuccess(id)))
635 .catch(error => dispatch(rejectFollowRequestFail(id, error)));
639 export function rejectFollowRequestRequest(id) {
641 type: FOLLOW_REQUEST_REJECT_REQUEST,
646 export function rejectFollowRequestSuccess(id) {
648 type: FOLLOW_REQUEST_REJECT_SUCCESS,
653 export function rejectFollowRequestFail(id, error) {
655 type: FOLLOW_REQUEST_REJECT_FAIL,