The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

771 lines
19 KiB

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