The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

763 lines
19 KiB

  1. import api, { getLinks } from '../api'
  2. import Immutable from 'immutable';
  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. export const ACCOUNT_FOLLOW_REQUEST = 'ACCOUNT_FOLLOW_REQUEST';
  7. export const ACCOUNT_FOLLOW_SUCCESS = 'ACCOUNT_FOLLOW_SUCCESS';
  8. export const ACCOUNT_FOLLOW_FAIL = 'ACCOUNT_FOLLOW_FAIL';
  9. export const ACCOUNT_UNFOLLOW_REQUEST = 'ACCOUNT_UNFOLLOW_REQUEST';
  10. export const ACCOUNT_UNFOLLOW_SUCCESS = 'ACCOUNT_UNFOLLOW_SUCCESS';
  11. export const ACCOUNT_UNFOLLOW_FAIL = 'ACCOUNT_UNFOLLOW_FAIL';
  12. export const ACCOUNT_BLOCK_REQUEST = 'ACCOUNT_BLOCK_REQUEST';
  13. export const ACCOUNT_BLOCK_SUCCESS = 'ACCOUNT_BLOCK_SUCCESS';
  14. export const ACCOUNT_BLOCK_FAIL = 'ACCOUNT_BLOCK_FAIL';
  15. export const ACCOUNT_UNBLOCK_REQUEST = 'ACCOUNT_UNBLOCK_REQUEST';
  16. export const ACCOUNT_UNBLOCK_SUCCESS = 'ACCOUNT_UNBLOCK_SUCCESS';
  17. export const ACCOUNT_UNBLOCK_FAIL = 'ACCOUNT_UNBLOCK_FAIL';
  18. export const ACCOUNT_MUTE_REQUEST = 'ACCOUNT_MUTE_REQUEST';
  19. export const ACCOUNT_MUTE_SUCCESS = 'ACCOUNT_MUTE_SUCCESS';
  20. export const ACCOUNT_MUTE_FAIL = 'ACCOUNT_MUTE_FAIL';
  21. export const ACCOUNT_UNMUTE_REQUEST = 'ACCOUNT_UNMUTE_REQUEST';
  22. export const ACCOUNT_UNMUTE_SUCCESS = 'ACCOUNT_UNMUTE_SUCCESS';
  23. export const ACCOUNT_UNMUTE_FAIL = 'ACCOUNT_UNMUTE_FAIL';
  24. export const ACCOUNT_TIMELINE_FETCH_REQUEST = 'ACCOUNT_TIMELINE_FETCH_REQUEST';
  25. export const ACCOUNT_TIMELINE_FETCH_SUCCESS = 'ACCOUNT_TIMELINE_FETCH_SUCCESS';
  26. export const ACCOUNT_TIMELINE_FETCH_FAIL = 'ACCOUNT_TIMELINE_FETCH_FAIL';
  27. export const ACCOUNT_TIMELINE_EXPAND_REQUEST = 'ACCOUNT_TIMELINE_EXPAND_REQUEST';
  28. export const ACCOUNT_TIMELINE_EXPAND_SUCCESS = 'ACCOUNT_TIMELINE_EXPAND_SUCCESS';
  29. export const ACCOUNT_TIMELINE_EXPAND_FAIL = 'ACCOUNT_TIMELINE_EXPAND_FAIL';
  30. export const FOLLOWERS_FETCH_REQUEST = 'FOLLOWERS_FETCH_REQUEST';
  31. export const FOLLOWERS_FETCH_SUCCESS = 'FOLLOWERS_FETCH_SUCCESS';
  32. export const FOLLOWERS_FETCH_FAIL = 'FOLLOWERS_FETCH_FAIL';
  33. export const FOLLOWERS_EXPAND_REQUEST = 'FOLLOWERS_EXPAND_REQUEST';
  34. export const FOLLOWERS_EXPAND_SUCCESS = 'FOLLOWERS_EXPAND_SUCCESS';
  35. export const FOLLOWERS_EXPAND_FAIL = 'FOLLOWERS_EXPAND_FAIL';
  36. export const FOLLOWING_FETCH_REQUEST = 'FOLLOWING_FETCH_REQUEST';
  37. export const FOLLOWING_FETCH_SUCCESS = 'FOLLOWING_FETCH_SUCCESS';
  38. export const FOLLOWING_FETCH_FAIL = 'FOLLOWING_FETCH_FAIL';
  39. export const FOLLOWING_EXPAND_REQUEST = 'FOLLOWING_EXPAND_REQUEST';
  40. export const FOLLOWING_EXPAND_SUCCESS = 'FOLLOWING_EXPAND_SUCCESS';
  41. export const FOLLOWING_EXPAND_FAIL = 'FOLLOWING_EXPAND_FAIL';
  42. export const RELATIONSHIPS_FETCH_REQUEST = 'RELATIONSHIPS_FETCH_REQUEST';
  43. export const RELATIONSHIPS_FETCH_SUCCESS = 'RELATIONSHIPS_FETCH_SUCCESS';
  44. export const RELATIONSHIPS_FETCH_FAIL = 'RELATIONSHIPS_FETCH_FAIL';
  45. export const FOLLOW_REQUESTS_FETCH_REQUEST = 'FOLLOW_REQUESTS_FETCH_REQUEST';
  46. export const FOLLOW_REQUESTS_FETCH_SUCCESS = 'FOLLOW_REQUESTS_FETCH_SUCCESS';
  47. export const FOLLOW_REQUESTS_FETCH_FAIL = 'FOLLOW_REQUESTS_FETCH_FAIL';
  48. export const FOLLOW_REQUESTS_EXPAND_REQUEST = 'FOLLOW_REQUESTS_EXPAND_REQUEST';
  49. export const FOLLOW_REQUESTS_EXPAND_SUCCESS = 'FOLLOW_REQUESTS_EXPAND_SUCCESS';
  50. export const FOLLOW_REQUESTS_EXPAND_FAIL = 'FOLLOW_REQUESTS_EXPAND_FAIL';
  51. export const FOLLOW_REQUEST_AUTHORIZE_REQUEST = 'FOLLOW_REQUEST_AUTHORIZE_REQUEST';
  52. export const FOLLOW_REQUEST_AUTHORIZE_SUCCESS = 'FOLLOW_REQUEST_AUTHORIZE_SUCCESS';
  53. export const FOLLOW_REQUEST_AUTHORIZE_FAIL = 'FOLLOW_REQUEST_AUTHORIZE_FAIL';
  54. export const FOLLOW_REQUEST_REJECT_REQUEST = 'FOLLOW_REQUEST_REJECT_REQUEST';
  55. export const FOLLOW_REQUEST_REJECT_SUCCESS = 'FOLLOW_REQUEST_REJECT_SUCCESS';
  56. export const FOLLOW_REQUEST_REJECT_FAIL = 'FOLLOW_REQUEST_REJECT_FAIL';
  57. export function fetchAccount(id) {
  58. return (dispatch, getState) => {
  59. dispatch(fetchRelationships([id]));
  60. if (getState().getIn(['accounts', id], null) !== null) {
  61. return;
  62. }
  63. dispatch(fetchAccountRequest(id));
  64. api(getState).get(`/api/v1/accounts/${id}`).then(response => {
  65. dispatch(fetchAccountSuccess(response.data));
  66. }).catch(error => {
  67. dispatch(fetchAccountFail(id, error));
  68. });
  69. };
  70. };
  71. export function fetchAccountTimeline(id, replace = false) {
  72. return (dispatch, getState) => {
  73. const ids = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List());
  74. const newestId = ids.size > 0 ? ids.first() : null;
  75. let params = '';
  76. let skipLoading = false;
  77. if (newestId !== null && !replace) {
  78. params = `?since_id=${newestId}`;
  79. skipLoading = true;
  80. }
  81. dispatch(fetchAccountTimelineRequest(id, skipLoading));
  82. api(getState).get(`/api/v1/accounts/${id}/statuses${params}`).then(response => {
  83. dispatch(fetchAccountTimelineSuccess(id, response.data, replace, skipLoading));
  84. }).catch(error => {
  85. dispatch(fetchAccountTimelineFail(id, error, skipLoading));
  86. });
  87. };
  88. };
  89. export function expandAccountTimeline(id) {
  90. return (dispatch, getState) => {
  91. const lastId = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List()).last();
  92. dispatch(expandAccountTimelineRequest(id));
  93. api(getState).get(`/api/v1/accounts/${id}/statuses`, {
  94. params: {
  95. limit: 10,
  96. max_id: lastId
  97. }
  98. }).then(response => {
  99. const next = getLinks(response).refs.find(link => link.rel === 'next');
  100. dispatch(expandAccountTimelineSuccess(id, response.data, next));
  101. }).catch(error => {
  102. dispatch(expandAccountTimelineFail(id, error));
  103. });
  104. };
  105. };
  106. export function fetchAccountRequest(id) {
  107. return {
  108. type: ACCOUNT_FETCH_REQUEST,
  109. id
  110. };
  111. };
  112. export function fetchAccountSuccess(account) {
  113. return {
  114. type: ACCOUNT_FETCH_SUCCESS,
  115. account
  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. export function followAccount(id) {
  127. return (dispatch, getState) => {
  128. dispatch(followAccountRequest(id));
  129. api(getState).post(`/api/v1/accounts/${id}/follow`).then(response => {
  130. dispatch(followAccountSuccess(response.data));
  131. }).catch(error => {
  132. dispatch(followAccountFail(error));
  133. });
  134. };
  135. };
  136. export function unfollowAccount(id) {
  137. return (dispatch, getState) => {
  138. dispatch(unfollowAccountRequest(id));
  139. api(getState).post(`/api/v1/accounts/${id}/unfollow`).then(response => {
  140. dispatch(unfollowAccountSuccess(response.data));
  141. }).catch(error => {
  142. dispatch(unfollowAccountFail(error));
  143. });
  144. }
  145. };
  146. export function followAccountRequest(id) {
  147. return {
  148. type: ACCOUNT_FOLLOW_REQUEST,
  149. id
  150. };
  151. };
  152. export function followAccountSuccess(relationship) {
  153. return {
  154. type: ACCOUNT_FOLLOW_SUCCESS,
  155. relationship
  156. };
  157. };
  158. export function followAccountFail(error) {
  159. return {
  160. type: ACCOUNT_FOLLOW_FAIL,
  161. error
  162. };
  163. };
  164. export function unfollowAccountRequest(id) {
  165. return {
  166. type: ACCOUNT_UNFOLLOW_REQUEST,
  167. id
  168. };
  169. };
  170. export function unfollowAccountSuccess(relationship) {
  171. return {
  172. type: ACCOUNT_UNFOLLOW_SUCCESS,
  173. relationship
  174. };
  175. };
  176. export function unfollowAccountFail(error) {
  177. return {
  178. type: ACCOUNT_UNFOLLOW_FAIL,
  179. error
  180. };
  181. };
  182. export function fetchAccountTimelineRequest(id, skipLoading) {
  183. return {
  184. type: ACCOUNT_TIMELINE_FETCH_REQUEST,
  185. id,
  186. skipLoading
  187. };
  188. };
  189. export function fetchAccountTimelineSuccess(id, statuses, replace, skipLoading) {
  190. return {
  191. type: ACCOUNT_TIMELINE_FETCH_SUCCESS,
  192. id,
  193. statuses,
  194. replace,
  195. skipLoading
  196. };
  197. };
  198. export function fetchAccountTimelineFail(id, error, skipLoading) {
  199. return {
  200. type: ACCOUNT_TIMELINE_FETCH_FAIL,
  201. id,
  202. error,
  203. skipLoading,
  204. skipAlert: error.response.status === 404
  205. };
  206. };
  207. export function expandAccountTimelineRequest(id) {
  208. return {
  209. type: ACCOUNT_TIMELINE_EXPAND_REQUEST,
  210. id
  211. };
  212. };
  213. export function expandAccountTimelineSuccess(id, statuses, next) {
  214. return {
  215. type: ACCOUNT_TIMELINE_EXPAND_SUCCESS,
  216. id,
  217. statuses,
  218. next
  219. };
  220. };
  221. export function expandAccountTimelineFail(id, error) {
  222. return {
  223. type: ACCOUNT_TIMELINE_EXPAND_FAIL,
  224. id,
  225. error
  226. };
  227. };
  228. export function blockAccount(id) {
  229. return (dispatch, getState) => {
  230. dispatch(blockAccountRequest(id));
  231. api(getState).post(`/api/v1/accounts/${id}/block`).then(response => {
  232. // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers
  233. dispatch(blockAccountSuccess(response.data, getState().get('statuses')));
  234. }).catch(error => {
  235. dispatch(blockAccountFail(id, error));
  236. });
  237. };
  238. };
  239. export function unblockAccount(id) {
  240. return (dispatch, getState) => {
  241. dispatch(unblockAccountRequest(id));
  242. api(getState).post(`/api/v1/accounts/${id}/unblock`).then(response => {
  243. dispatch(unblockAccountSuccess(response.data));
  244. }).catch(error => {
  245. dispatch(unblockAccountFail(id, error));
  246. });
  247. };
  248. };
  249. export function blockAccountRequest(id) {
  250. return {
  251. type: ACCOUNT_BLOCK_REQUEST,
  252. id
  253. };
  254. };
  255. export function blockAccountSuccess(relationship, statuses) {
  256. return {
  257. type: ACCOUNT_BLOCK_SUCCESS,
  258. relationship,
  259. statuses
  260. };
  261. };
  262. export function blockAccountFail(error) {
  263. return {
  264. type: ACCOUNT_BLOCK_FAIL,
  265. error
  266. };
  267. };
  268. export function unblockAccountRequest(id) {
  269. return {
  270. type: ACCOUNT_UNBLOCK_REQUEST,
  271. id
  272. };
  273. };
  274. export function unblockAccountSuccess(relationship) {
  275. return {
  276. type: ACCOUNT_UNBLOCK_SUCCESS,
  277. relationship
  278. };
  279. };
  280. export function unblockAccountFail(error) {
  281. return {
  282. type: ACCOUNT_UNBLOCK_FAIL,
  283. error
  284. };
  285. };
  286. export function muteAccount(id) {
  287. return (dispatch, getState) => {
  288. dispatch(muteAccountRequest(id));
  289. api(getState).post(`/api/v1/accounts/${id}/mute`).then(response => {
  290. // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers
  291. dispatch(muteAccountSuccess(response.data, getState().get('statuses')));
  292. }).catch(error => {
  293. dispatch(muteAccountFail(id, error));
  294. });
  295. };
  296. };
  297. export function unmuteAccount(id) {
  298. return (dispatch, getState) => {
  299. dispatch(unmuteAccountRequest(id));
  300. api(getState).post(`/api/v1/accounts/${id}/unmute`).then(response => {
  301. dispatch(unmuteAccountSuccess(response.data));
  302. }).catch(error => {
  303. dispatch(unmuteAccountFail(id, error));
  304. });
  305. };
  306. };
  307. export function muteAccountRequest(id) {
  308. return {
  309. type: ACCOUNT_MUTE_REQUEST,
  310. id
  311. };
  312. };
  313. export function muteAccountSuccess(relationship, statuses) {
  314. return {
  315. type: ACCOUNT_MUTE_SUCCESS,
  316. relationship,
  317. statuses
  318. };
  319. };
  320. export function muteAccountFail(error) {
  321. return {
  322. type: ACCOUNT_MUTE_FAIL,
  323. error
  324. };
  325. };
  326. export function unmuteAccountRequest(id) {
  327. return {
  328. type: ACCOUNT_UNMUTE_REQUEST,
  329. id
  330. };
  331. };
  332. export function unmuteAccountSuccess(relationship) {
  333. return {
  334. type: ACCOUNT_UNMUTE_SUCCESS,
  335. relationship
  336. };
  337. };
  338. export function unmuteAccountFail(error) {
  339. return {
  340. type: ACCOUNT_UNMUTE_FAIL,
  341. error
  342. };
  343. };
  344. export function fetchFollowers(id) {
  345. return (dispatch, getState) => {
  346. dispatch(fetchFollowersRequest(id));
  347. api(getState).get(`/api/v1/accounts/${id}/followers`).then(response => {
  348. const next = getLinks(response).refs.find(link => link.rel === 'next');
  349. dispatch(fetchFollowersSuccess(id, response.data, next ? next.uri : null));
  350. dispatch(fetchRelationships(response.data.map(item => item.id)));
  351. }).catch(error => {
  352. dispatch(fetchFollowersFail(id, error));
  353. });
  354. };
  355. };
  356. export function fetchFollowersRequest(id) {
  357. return {
  358. type: FOLLOWERS_FETCH_REQUEST,
  359. id
  360. };
  361. };
  362. export function fetchFollowersSuccess(id, accounts, next) {
  363. return {
  364. type: FOLLOWERS_FETCH_SUCCESS,
  365. id,
  366. accounts,
  367. next
  368. };
  369. };
  370. export function fetchFollowersFail(id, error) {
  371. return {
  372. type: FOLLOWERS_FETCH_FAIL,
  373. id,
  374. error
  375. };
  376. };
  377. export function expandFollowers(id) {
  378. return (dispatch, getState) => {
  379. const url = getState().getIn(['user_lists', 'followers', id, 'next']);
  380. if (url === null) {
  381. return;
  382. }
  383. dispatch(expandFollowersRequest(id));
  384. api(getState).get(url).then(response => {
  385. 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)));
  388. }).catch(error => {
  389. dispatch(expandFollowersFail(id, error));
  390. });
  391. };
  392. };
  393. export function expandFollowersRequest(id) {
  394. return {
  395. type: FOLLOWERS_EXPAND_REQUEST,
  396. id
  397. };
  398. };
  399. export function expandFollowersSuccess(id, accounts, next) {
  400. return {
  401. type: FOLLOWERS_EXPAND_SUCCESS,
  402. id,
  403. accounts,
  404. next
  405. };
  406. };
  407. export function expandFollowersFail(id, error) {
  408. return {
  409. type: FOLLOWERS_EXPAND_FAIL,
  410. id,
  411. error
  412. };
  413. };
  414. export function fetchFollowing(id) {
  415. return (dispatch, getState) => {
  416. dispatch(fetchFollowingRequest(id));
  417. api(getState).get(`/api/v1/accounts/${id}/following`).then(response => {
  418. const next = getLinks(response).refs.find(link => link.rel === 'next');
  419. dispatch(fetchFollowingSuccess(id, response.data, next ? next.uri : null));
  420. dispatch(fetchRelationships(response.data.map(item => item.id)));
  421. }).catch(error => {
  422. dispatch(fetchFollowingFail(id, error));
  423. });
  424. };
  425. };
  426. export function fetchFollowingRequest(id) {
  427. return {
  428. type: FOLLOWING_FETCH_REQUEST,
  429. id
  430. };
  431. };
  432. export function fetchFollowingSuccess(id, accounts, next) {
  433. return {
  434. type: FOLLOWING_FETCH_SUCCESS,
  435. id,
  436. accounts,
  437. next
  438. };
  439. };
  440. export function fetchFollowingFail(id, error) {
  441. return {
  442. type: FOLLOWING_FETCH_FAIL,
  443. id,
  444. error
  445. };
  446. };
  447. export function expandFollowing(id) {
  448. return (dispatch, getState) => {
  449. const url = getState().getIn(['user_lists', 'following', id, 'next']);
  450. if (url === null) {
  451. return;
  452. }
  453. dispatch(expandFollowingRequest(id));
  454. api(getState).get(url).then(response => {
  455. const next = getLinks(response).refs.find(link => link.rel === 'next');
  456. dispatch(expandFollowingSuccess(id, response.data, next ? next.uri : null));
  457. dispatch(fetchRelationships(response.data.map(item => item.id)));
  458. }).catch(error => {
  459. dispatch(expandFollowingFail(id, error));
  460. });
  461. };
  462. };
  463. export function expandFollowingRequest(id) {
  464. return {
  465. type: FOLLOWING_EXPAND_REQUEST,
  466. id
  467. };
  468. };
  469. export function expandFollowingSuccess(id, accounts, next) {
  470. return {
  471. type: FOLLOWING_EXPAND_SUCCESS,
  472. id,
  473. accounts,
  474. next
  475. };
  476. };
  477. export function expandFollowingFail(id, error) {
  478. return {
  479. type: FOLLOWING_EXPAND_FAIL,
  480. id,
  481. error
  482. };
  483. };
  484. export function fetchRelationships(accountIds) {
  485. return (dispatch, getState) => {
  486. const loadedRelationships = getState().get('relationships');
  487. const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null);
  488. if (newAccountIds.length === 0) {
  489. return;
  490. }
  491. dispatch(fetchRelationshipsRequest(newAccountIds));
  492. api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
  493. dispatch(fetchRelationshipsSuccess(response.data));
  494. }).catch(error => {
  495. dispatch(fetchRelationshipsFail(error));
  496. });
  497. };
  498. };
  499. export function fetchRelationshipsRequest(ids) {
  500. return {
  501. type: RELATIONSHIPS_FETCH_REQUEST,
  502. ids,
  503. skipLoading: true
  504. };
  505. };
  506. export function fetchRelationshipsSuccess(relationships) {
  507. return {
  508. type: RELATIONSHIPS_FETCH_SUCCESS,
  509. relationships,
  510. skipLoading: true
  511. };
  512. };
  513. export function fetchRelationshipsFail(error) {
  514. return {
  515. type: RELATIONSHIPS_FETCH_FAIL,
  516. error,
  517. skipLoading: true
  518. };
  519. };
  520. export function fetchFollowRequests() {
  521. return (dispatch, getState) => {
  522. dispatch(fetchFollowRequestsRequest());
  523. api(getState).get('/api/v1/follow_requests').then(response => {
  524. const next = getLinks(response).refs.find(link => link.rel === 'next');
  525. dispatch(fetchFollowRequestsSuccess(response.data, next ? next.uri : null))
  526. }).catch(error => dispatch(fetchFollowRequestsFail(error)));
  527. };
  528. };
  529. export function fetchFollowRequestsRequest() {
  530. return {
  531. type: FOLLOW_REQUESTS_FETCH_REQUEST
  532. };
  533. };
  534. export function fetchFollowRequestsSuccess(accounts, next) {
  535. return {
  536. type: FOLLOW_REQUESTS_FETCH_SUCCESS,
  537. accounts,
  538. next
  539. };
  540. };
  541. export function fetchFollowRequestsFail(error) {
  542. return {
  543. type: FOLLOW_REQUESTS_FETCH_FAIL,
  544. error
  545. };
  546. };
  547. export function expandFollowRequests() {
  548. return (dispatch, getState) => {
  549. const url = getState().getIn(['user_lists', 'follow_requests', 'next']);
  550. if (url === null) {
  551. return;
  552. }
  553. dispatch(expandFollowRequestsRequest());
  554. api(getState).get(url).then(response => {
  555. const next = getLinks(response).refs.find(link => link.rel === 'next');
  556. dispatch(expandFollowRequestsSuccess(response.data, next ? next.uri : null))
  557. }).catch(error => dispatch(expandFollowRequestsFail(error)));
  558. };
  559. };
  560. export function expandFollowRequestsRequest() {
  561. return {
  562. type: FOLLOW_REQUESTS_EXPAND_REQUEST
  563. };
  564. };
  565. export function expandFollowRequestsSuccess(accounts, next) {
  566. return {
  567. type: FOLLOW_REQUESTS_EXPAND_SUCCESS,
  568. accounts,
  569. next
  570. };
  571. };
  572. export function expandFollowRequestsFail(error) {
  573. return {
  574. type: FOLLOW_REQUESTS_EXPAND_FAIL,
  575. error
  576. };
  577. };
  578. export function authorizeFollowRequest(id) {
  579. return (dispatch, getState) => {
  580. dispatch(authorizeFollowRequestRequest(id));
  581. api(getState)
  582. .post(`/api/v1/follow_requests/${id}/authorize`)
  583. .then(response => dispatch(authorizeFollowRequestSuccess(id)))
  584. .catch(error => dispatch(authorizeFollowRequestFail(id, error)));
  585. };
  586. };
  587. export function authorizeFollowRequestRequest(id) {
  588. return {
  589. type: FOLLOW_REQUEST_AUTHORIZE_REQUEST,
  590. id
  591. };
  592. };
  593. export function authorizeFollowRequestSuccess(id) {
  594. return {
  595. type: FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
  596. id
  597. };
  598. };
  599. export function authorizeFollowRequestFail(id, error) {
  600. return {
  601. type: FOLLOW_REQUEST_AUTHORIZE_FAIL,
  602. id,
  603. error
  604. };
  605. };
  606. export function rejectFollowRequest(id) {
  607. return (dispatch, getState) => {
  608. dispatch(rejectFollowRequestRequest(id));
  609. api(getState)
  610. .post(`/api/v1/follow_requests/${id}/reject`)
  611. .then(response => dispatch(rejectFollowRequestSuccess(id)))
  612. .catch(error => dispatch(rejectFollowRequestFail(id, error)));
  613. };
  614. };
  615. export function rejectFollowRequestRequest(id) {
  616. return {
  617. type: FOLLOW_REQUEST_REJECT_REQUEST,
  618. id
  619. };
  620. };
  621. export function rejectFollowRequestSuccess(id) {
  622. return {
  623. type: FOLLOW_REQUEST_REJECT_SUCCESS,
  624. id
  625. };
  626. };
  627. export function rejectFollowRequestFail(id, error) {
  628. return {
  629. type: FOLLOW_REQUEST_REJECT_FAIL,
  630. id,
  631. error
  632. };
  633. };