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.

819 lines
20 KiB

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