accounts.js 20 KB

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