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.

280 lines
6.8 KiB

  1. import api from '../api'
  2. import axios from 'axios';
  3. export const ACCOUNT_SET_SELF = 'ACCOUNT_SET_SELF';
  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_TIMELINE_FETCH_REQUEST = 'ACCOUNT_TIMELINE_FETCH_REQUEST';
  20. export const ACCOUNT_TIMELINE_FETCH_SUCCESS = 'ACCOUNT_TIMELINE_FETCH_SUCCESS';
  21. export const ACCOUNT_TIMELINE_FETCH_FAIL = 'ACCOUNT_TIMELINE_FETCH_FAIL';
  22. export const ACCOUNT_TIMELINE_EXPAND_REQUEST = 'ACCOUNT_TIMELINE_EXPAND_REQUEST';
  23. export const ACCOUNT_TIMELINE_EXPAND_SUCCESS = 'ACCOUNT_TIMELINE_EXPAND_SUCCESS';
  24. export const ACCOUNT_TIMELINE_EXPAND_FAIL = 'ACCOUNT_TIMELINE_EXPAND_FAIL';
  25. export function setAccountSelf(account) {
  26. return {
  27. type: ACCOUNT_SET_SELF,
  28. account: account
  29. };
  30. };
  31. export function fetchAccount(id) {
  32. return (dispatch, getState) => {
  33. const boundApi = api(getState);
  34. dispatch(fetchAccountRequest(id));
  35. axios.all([boundApi.get(`/api/v1/accounts/${id}`), boundApi.get(`/api/v1/accounts/relationships?id=${id}`)]).then(values => {
  36. dispatch(fetchAccountSuccess(values[0].data, values[1].data[0]));
  37. }).catch(error => {
  38. dispatch(fetchAccountFail(id, error));
  39. });
  40. };
  41. };
  42. export function fetchAccountTimeline(id) {
  43. return (dispatch, getState) => {
  44. dispatch(fetchAccountTimelineRequest(id));
  45. api(getState).get(`/api/v1/accounts/${id}/statuses`).then(response => {
  46. dispatch(fetchAccountTimelineSuccess(id, response.data));
  47. }).catch(error => {
  48. dispatch(fetchAccountTimelineFail(id, error));
  49. });
  50. };
  51. };
  52. export function expandAccountTimeline(id) {
  53. return (dispatch, getState) => {
  54. const lastId = getState().getIn(['timelines', 'accounts_timelines', id]).last();
  55. dispatch(expandAccountTimelineRequest(id));
  56. api(getState).get(`/api/v1/accounts/${id}/statuses?max_id=${lastId}`).then(response => {
  57. dispatch(expandAccountTimelineSuccess(id, response.data));
  58. }).catch(error => {
  59. dispatch(expandAccountTimelineFail(id, error));
  60. });
  61. };
  62. };
  63. export function fetchAccountRequest(id) {
  64. return {
  65. type: ACCOUNT_FETCH_REQUEST,
  66. id: id
  67. };
  68. };
  69. export function fetchAccountSuccess(account, relationship) {
  70. return {
  71. type: ACCOUNT_FETCH_SUCCESS,
  72. account: account,
  73. relationship: relationship
  74. };
  75. };
  76. export function fetchAccountFail(id, error) {
  77. return {
  78. type: ACCOUNT_FETCH_FAIL,
  79. id: id,
  80. error: error
  81. };
  82. };
  83. export function followAccount(id) {
  84. return (dispatch, getState) => {
  85. dispatch(followAccountRequest(id));
  86. api(getState).post(`/api/v1/accounts/${id}/follow`).then(response => {
  87. dispatch(followAccountSuccess(response.data));
  88. }).catch(error => {
  89. dispatch(followAccountFail(error));
  90. });
  91. };
  92. };
  93. export function unfollowAccount(id) {
  94. return (dispatch, getState) => {
  95. dispatch(unfollowAccountRequest(id));
  96. api(getState).post(`/api/v1/accounts/${id}/unfollow`).then(response => {
  97. dispatch(unfollowAccountSuccess(response.data));
  98. }).catch(error => {
  99. dispatch(unfollowAccountFail(error));
  100. });
  101. }
  102. };
  103. export function followAccountRequest(id) {
  104. return {
  105. type: ACCOUNT_FOLLOW_REQUEST,
  106. id: id
  107. };
  108. };
  109. export function followAccountSuccess(relationship) {
  110. return {
  111. type: ACCOUNT_FOLLOW_SUCCESS,
  112. relationship: relationship
  113. };
  114. };
  115. export function followAccountFail(error) {
  116. return {
  117. type: ACCOUNT_FOLLOW_FAIL,
  118. error: error
  119. };
  120. };
  121. export function unfollowAccountRequest(id) {
  122. return {
  123. type: ACCOUNT_UNFOLLOW_REQUEST,
  124. id: id
  125. };
  126. };
  127. export function unfollowAccountSuccess(relationship) {
  128. return {
  129. type: ACCOUNT_UNFOLLOW_SUCCESS,
  130. relationship: relationship
  131. };
  132. };
  133. export function unfollowAccountFail(error) {
  134. return {
  135. type: ACCOUNT_UNFOLLOW_FAIL,
  136. error: error
  137. };
  138. };
  139. export function fetchAccountTimelineRequest(id) {
  140. return {
  141. type: ACCOUNT_TIMELINE_FETCH_REQUEST,
  142. id: id
  143. };
  144. };
  145. export function fetchAccountTimelineSuccess(id, statuses) {
  146. return {
  147. type: ACCOUNT_TIMELINE_FETCH_SUCCESS,
  148. id: id,
  149. statuses: statuses
  150. };
  151. };
  152. export function fetchAccountTimelineFail(id, error) {
  153. return {
  154. type: ACCOUNT_TIMELINE_FETCH_FAIL,
  155. id: id,
  156. error: error
  157. };
  158. };
  159. export function expandAccountTimelineRequest(id) {
  160. return {
  161. type: ACCOUNT_TIMELINE_EXPAND_REQUEST,
  162. id: id
  163. };
  164. };
  165. export function expandAccountTimelineSuccess(id, statuses) {
  166. return {
  167. type: ACCOUNT_TIMELINE_EXPAND_SUCCESS,
  168. id: id,
  169. statuses: statuses
  170. };
  171. };
  172. export function expandAccountTimelineFail(id, error) {
  173. return {
  174. type: ACCOUNT_TIMELINE_EXPAND_FAIL,
  175. id: id,
  176. error: error
  177. };
  178. };
  179. export function blockAccount(id) {
  180. return (dispatch, getState) => {
  181. dispatch(blockAccountRequest(id));
  182. api(getState).post(`/api/v1/accounts/${id}/block`).then(response => {
  183. dispatch(blockAccountSuccess(response.data));
  184. }).catch(error => {
  185. dispatch(blockAccountFail(id, error));
  186. });
  187. };
  188. };
  189. export function unblockAccount(id) {
  190. return (dispatch, getState) => {
  191. dispatch(unblockAccountRequest(id));
  192. api(getState).post(`/api/v1/accounts/${id}/unblock`).then(response => {
  193. dispatch(unblockAccountSuccess(response.data));
  194. }).catch(error => {
  195. dispatch(unblockAccountFail(id, error));
  196. });
  197. };
  198. };
  199. export function blockAccountRequest(id) {
  200. return {
  201. type: ACCOUNT_BLOCK_REQUEST,
  202. id: id
  203. };
  204. };
  205. export function blockAccountSuccess(relationship) {
  206. return {
  207. type: ACCOUNT_BLOCK_SUCCESS,
  208. relationship: relationship
  209. };
  210. };
  211. export function blockAccountFail(error) {
  212. return {
  213. type: ACCOUNT_BLOCK_FAIL,
  214. error: error
  215. };
  216. };
  217. export function unblockAccountRequest(id) {
  218. return {
  219. type: ACCOUNT_UNBLOCK_REQUEST,
  220. id: id
  221. };
  222. };
  223. export function unblockAccountSuccess(relationship) {
  224. return {
  225. type: ACCOUNT_UNBLOCK_SUCCESS,
  226. relationship: relationship
  227. };
  228. };
  229. export function unblockAccountFail(error) {
  230. return {
  231. type: ACCOUNT_UNBLOCK_FAIL,
  232. error: error
  233. };
  234. };