闭社主体 forked from https://github.com/tootsuite/mastodon
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.

760 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. 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(accountIds) {
  483. return (dispatch, getState) => {
  484. const loadedRelationships = getState().get('relationships');
  485. const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null);
  486. if (newAccountIds.length === 0) {
  487. return;
  488. }
  489. dispatch(fetchRelationshipsRequest(newAccountIds));
  490. api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
  491. dispatch(fetchRelationshipsSuccess(response.data));
  492. }).catch(error => {
  493. dispatch(fetchRelationshipsFail(error));
  494. });
  495. };
  496. };
  497. export function fetchRelationshipsRequest(ids) {
  498. return {
  499. type: RELATIONSHIPS_FETCH_REQUEST,
  500. ids,
  501. skipLoading: true
  502. };
  503. };
  504. export function fetchRelationshipsSuccess(relationships) {
  505. return {
  506. type: RELATIONSHIPS_FETCH_SUCCESS,
  507. relationships,
  508. skipLoading: true
  509. };
  510. };
  511. export function fetchRelationshipsFail(error) {
  512. return {
  513. type: RELATIONSHIPS_FETCH_FAIL,
  514. error,
  515. skipLoading: true
  516. };
  517. };
  518. export function fetchFollowRequests() {
  519. return (dispatch, getState) => {
  520. dispatch(fetchFollowRequestsRequest());
  521. api(getState).get('/api/v1/follow_requests').then(response => {
  522. const next = getLinks(response).refs.find(link => link.rel === 'next');
  523. dispatch(fetchFollowRequestsSuccess(response.data, next ? next.uri : null))
  524. }).catch(error => dispatch(fetchFollowRequestsFail(error)));
  525. };
  526. };
  527. export function fetchFollowRequestsRequest() {
  528. return {
  529. type: FOLLOW_REQUESTS_FETCH_REQUEST
  530. };
  531. };
  532. export function fetchFollowRequestsSuccess(accounts, next) {
  533. return {
  534. type: FOLLOW_REQUESTS_FETCH_SUCCESS,
  535. accounts,
  536. next
  537. };
  538. };
  539. export function fetchFollowRequestsFail(error) {
  540. return {
  541. type: FOLLOW_REQUESTS_FETCH_FAIL,
  542. error
  543. };
  544. };
  545. export function expandFollowRequests() {
  546. return (dispatch, getState) => {
  547. const url = getState().getIn(['user_lists', 'follow_requests', 'next']);
  548. if (url === null) {
  549. return;
  550. }
  551. dispatch(expandFollowRequestsRequest());
  552. api(getState).get(url).then(response => {
  553. const next = getLinks(response).refs.find(link => link.rel === 'next');
  554. dispatch(expandFollowRequestsSuccess(response.data, next ? next.uri : null))
  555. }).catch(error => dispatch(expandFollowRequestsFail(error)));
  556. };
  557. };
  558. export function expandFollowRequestsRequest() {
  559. return {
  560. type: FOLLOW_REQUESTS_EXPAND_REQUEST
  561. };
  562. };
  563. export function expandFollowRequestsSuccess(accounts, next) {
  564. return {
  565. type: FOLLOW_REQUESTS_EXPAND_SUCCESS,
  566. accounts,
  567. next
  568. };
  569. };
  570. export function expandFollowRequestsFail(error) {
  571. return {
  572. type: FOLLOW_REQUESTS_EXPAND_FAIL,
  573. error
  574. };
  575. };
  576. export function authorizeFollowRequest(id) {
  577. return (dispatch, getState) => {
  578. dispatch(authorizeFollowRequestRequest(id));
  579. api(getState)
  580. .post(`/api/v1/follow_requests/${id}/authorize`)
  581. .then(response => dispatch(authorizeFollowRequestSuccess(id)))
  582. .catch(error => dispatch(authorizeFollowRequestFail(id, error)));
  583. };
  584. };
  585. export function authorizeFollowRequestRequest(id) {
  586. return {
  587. type: FOLLOW_REQUEST_AUTHORIZE_REQUEST,
  588. id
  589. };
  590. };
  591. export function authorizeFollowRequestSuccess(id) {
  592. return {
  593. type: FOLLOW_REQUEST_AUTHORIZE_SUCCESS,
  594. id
  595. };
  596. };
  597. export function authorizeFollowRequestFail(id, error) {
  598. return {
  599. type: FOLLOW_REQUEST_AUTHORIZE_FAIL,
  600. id,
  601. error
  602. };
  603. };
  604. export function rejectFollowRequest(id) {
  605. return (dispatch, getState) => {
  606. dispatch(rejectFollowRequestRequest(id));
  607. api(getState)
  608. .post(`/api/v1/follow_requests/${id}/reject`)
  609. .then(response => dispatch(rejectFollowRequestSuccess(id)))
  610. .catch(error => dispatch(rejectFollowRequestFail(id, error)));
  611. };
  612. };
  613. export function rejectFollowRequestRequest(id) {
  614. return {
  615. type: FOLLOW_REQUEST_REJECT_REQUEST,
  616. id
  617. };
  618. };
  619. export function rejectFollowRequestSuccess(id) {
  620. return {
  621. type: FOLLOW_REQUEST_REJECT_SUCCESS,
  622. id
  623. };
  624. };
  625. export function rejectFollowRequestFail(id, error) {
  626. return {
  627. type: FOLLOW_REQUEST_REJECT_FAIL,
  628. id,
  629. error
  630. };
  631. };