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.

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