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.

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