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.
 
 
 
 

314 lines
7.0 KiB

  1. import api from '../api';
  2. export const REBLOG_REQUEST = 'REBLOG_REQUEST';
  3. export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
  4. export const REBLOG_FAIL = 'REBLOG_FAIL';
  5. export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
  6. export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
  7. export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
  8. export const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST';
  9. export const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS';
  10. export const UNREBLOG_FAIL = 'UNREBLOG_FAIL';
  11. export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST';
  12. export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS';
  13. export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL';
  14. export const REBLOGS_FETCH_REQUEST = 'REBLOGS_FETCH_REQUEST';
  15. export const REBLOGS_FETCH_SUCCESS = 'REBLOGS_FETCH_SUCCESS';
  16. export const REBLOGS_FETCH_FAIL = 'REBLOGS_FETCH_FAIL';
  17. export const FAVOURITES_FETCH_REQUEST = 'FAVOURITES_FETCH_REQUEST';
  18. export const FAVOURITES_FETCH_SUCCESS = 'FAVOURITES_FETCH_SUCCESS';
  19. export const FAVOURITES_FETCH_FAIL = 'FAVOURITES_FETCH_FAIL';
  20. export const PIN_REQUEST = 'PIN_REQUEST';
  21. export const PIN_SUCCESS = 'PIN_SUCCESS';
  22. export const PIN_FAIL = 'PIN_FAIL';
  23. export const UNPIN_REQUEST = 'UNPIN_REQUEST';
  24. export const UNPIN_SUCCESS = 'UNPIN_SUCCESS';
  25. export const UNPIN_FAIL = 'UNPIN_FAIL';
  26. export function reblog(status) {
  27. return function (dispatch, getState) {
  28. dispatch(reblogRequest(status));
  29. api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then(function (response) {
  30. // The reblog API method returns a new status wrapped around the original. In this case we are only
  31. // interested in how the original is modified, hence passing it skipping the wrapper
  32. dispatch(reblogSuccess(status, response.data.reblog));
  33. }).catch(function (error) {
  34. dispatch(reblogFail(status, error));
  35. });
  36. };
  37. };
  38. export function unreblog(status) {
  39. return (dispatch, getState) => {
  40. dispatch(unreblogRequest(status));
  41. api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
  42. dispatch(unreblogSuccess(status, response.data));
  43. }).catch(error => {
  44. dispatch(unreblogFail(status, error));
  45. });
  46. };
  47. };
  48. export function reblogRequest(status) {
  49. return {
  50. type: REBLOG_REQUEST,
  51. status: status,
  52. };
  53. };
  54. export function reblogSuccess(status, response) {
  55. return {
  56. type: REBLOG_SUCCESS,
  57. status: status,
  58. response: response,
  59. };
  60. };
  61. export function reblogFail(status, error) {
  62. return {
  63. type: REBLOG_FAIL,
  64. status: status,
  65. error: error,
  66. };
  67. };
  68. export function unreblogRequest(status) {
  69. return {
  70. type: UNREBLOG_REQUEST,
  71. status: status,
  72. };
  73. };
  74. export function unreblogSuccess(status, response) {
  75. return {
  76. type: UNREBLOG_SUCCESS,
  77. status: status,
  78. response: response,
  79. };
  80. };
  81. export function unreblogFail(status, error) {
  82. return {
  83. type: UNREBLOG_FAIL,
  84. status: status,
  85. error: error,
  86. };
  87. };
  88. export function favourite(status) {
  89. return function (dispatch, getState) {
  90. dispatch(favouriteRequest(status));
  91. api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then(function (response) {
  92. dispatch(favouriteSuccess(status, response.data));
  93. }).catch(function (error) {
  94. dispatch(favouriteFail(status, error));
  95. });
  96. };
  97. };
  98. export function unfavourite(status) {
  99. return (dispatch, getState) => {
  100. dispatch(unfavouriteRequest(status));
  101. api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
  102. dispatch(unfavouriteSuccess(status, response.data));
  103. }).catch(error => {
  104. dispatch(unfavouriteFail(status, error));
  105. });
  106. };
  107. };
  108. export function favouriteRequest(status) {
  109. return {
  110. type: FAVOURITE_REQUEST,
  111. status: status,
  112. };
  113. };
  114. export function favouriteSuccess(status, response) {
  115. return {
  116. type: FAVOURITE_SUCCESS,
  117. status: status,
  118. response: response,
  119. };
  120. };
  121. export function favouriteFail(status, error) {
  122. return {
  123. type: FAVOURITE_FAIL,
  124. status: status,
  125. error: error,
  126. };
  127. };
  128. export function unfavouriteRequest(status) {
  129. return {
  130. type: UNFAVOURITE_REQUEST,
  131. status: status,
  132. };
  133. };
  134. export function unfavouriteSuccess(status, response) {
  135. return {
  136. type: UNFAVOURITE_SUCCESS,
  137. status: status,
  138. response: response,
  139. };
  140. };
  141. export function unfavouriteFail(status, error) {
  142. return {
  143. type: UNFAVOURITE_FAIL,
  144. status: status,
  145. error: error,
  146. };
  147. };
  148. export function fetchReblogs(id) {
  149. return (dispatch, getState) => {
  150. dispatch(fetchReblogsRequest(id));
  151. api(getState).get(`/api/v1/statuses/${id}/reblogged_by`).then(response => {
  152. dispatch(fetchReblogsSuccess(id, response.data));
  153. }).catch(error => {
  154. dispatch(fetchReblogsFail(id, error));
  155. });
  156. };
  157. };
  158. export function fetchReblogsRequest(id) {
  159. return {
  160. type: REBLOGS_FETCH_REQUEST,
  161. id,
  162. };
  163. };
  164. export function fetchReblogsSuccess(id, accounts) {
  165. return {
  166. type: REBLOGS_FETCH_SUCCESS,
  167. id,
  168. accounts,
  169. };
  170. };
  171. export function fetchReblogsFail(id, error) {
  172. return {
  173. type: REBLOGS_FETCH_FAIL,
  174. error,
  175. };
  176. };
  177. export function fetchFavourites(id) {
  178. return (dispatch, getState) => {
  179. dispatch(fetchFavouritesRequest(id));
  180. api(getState).get(`/api/v1/statuses/${id}/favourited_by`).then(response => {
  181. dispatch(fetchFavouritesSuccess(id, response.data));
  182. }).catch(error => {
  183. dispatch(fetchFavouritesFail(id, error));
  184. });
  185. };
  186. };
  187. export function fetchFavouritesRequest(id) {
  188. return {
  189. type: FAVOURITES_FETCH_REQUEST,
  190. id,
  191. };
  192. };
  193. export function fetchFavouritesSuccess(id, accounts) {
  194. return {
  195. type: FAVOURITES_FETCH_SUCCESS,
  196. id,
  197. accounts,
  198. };
  199. };
  200. export function fetchFavouritesFail(id, error) {
  201. return {
  202. type: FAVOURITES_FETCH_FAIL,
  203. error,
  204. };
  205. };
  206. export function pin(status) {
  207. return (dispatch, getState) => {
  208. dispatch(pinRequest(status));
  209. api(getState).post(`/api/v1/statuses/${status.get('id')}/pin`).then(response => {
  210. dispatch(pinSuccess(status, response.data));
  211. }).catch(error => {
  212. dispatch(pinFail(status, error));
  213. });
  214. };
  215. };
  216. export function pinRequest(status) {
  217. return {
  218. type: PIN_REQUEST,
  219. status,
  220. };
  221. };
  222. export function pinSuccess(status, response) {
  223. return {
  224. type: PIN_SUCCESS,
  225. status,
  226. response,
  227. };
  228. };
  229. export function pinFail(status, error) {
  230. return {
  231. type: PIN_FAIL,
  232. status,
  233. error,
  234. };
  235. };
  236. export function unpin (status) {
  237. return (dispatch, getState) => {
  238. dispatch(unpinRequest(status));
  239. api(getState).post(`/api/v1/statuses/${status.get('id')}/unpin`).then(response => {
  240. dispatch(unpinSuccess(status, response.data));
  241. }).catch(error => {
  242. dispatch(unpinFail(status, error));
  243. });
  244. };
  245. };
  246. export function unpinRequest(status) {
  247. return {
  248. type: UNPIN_REQUEST,
  249. status,
  250. };
  251. };
  252. export function unpinSuccess(status, response) {
  253. return {
  254. type: UNPIN_SUCCESS,
  255. status,
  256. response,
  257. };
  258. };
  259. export function unpinFail(status, error) {
  260. return {
  261. type: UNPIN_FAIL,
  262. status,
  263. error,
  264. };
  265. };