accounts.js 18 KB

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