logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

interactions.js (6176B)


  1. import api from '../api';
  2. import { importFetchedAccounts, importFetchedStatus } from './importer';
  3. export const REBLOG_REQUEST = 'REBLOG_REQUEST';
  4. export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
  5. export const REBLOG_FAIL = 'REBLOG_FAIL';
  6. export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
  7. export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
  8. export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
  9. export const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST';
  10. export const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS';
  11. export const UNREBLOG_FAIL = 'UNREBLOG_FAIL';
  12. export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST';
  13. export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS';
  14. export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL';
  15. export const REBLOGS_FETCH_REQUEST = 'REBLOGS_FETCH_REQUEST';
  16. export const REBLOGS_FETCH_SUCCESS = 'REBLOGS_FETCH_SUCCESS';
  17. export const REBLOGS_FETCH_FAIL = 'REBLOGS_FETCH_FAIL';
  18. export const FAVOURITES_FETCH_REQUEST = 'FAVOURITES_FETCH_REQUEST';
  19. export const FAVOURITES_FETCH_SUCCESS = 'FAVOURITES_FETCH_SUCCESS';
  20. export const FAVOURITES_FETCH_FAIL = 'FAVOURITES_FETCH_FAIL';
  21. export const PIN_REQUEST = 'PIN_REQUEST';
  22. export const PIN_SUCCESS = 'PIN_SUCCESS';
  23. export const PIN_FAIL = 'PIN_FAIL';
  24. export function reblog(status) {
  25. return function (dispatch, getState) {
  26. dispatch(reblogRequest(status));
  27. api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then(function (response) {
  28. // The reblog API method returns a new status wrapped around the original. In this case we are only
  29. // interested in how the original is modified, hence passing it skipping the wrapper
  30. dispatch(importFetchedStatus(response.data.reblog));
  31. dispatch(reblogSuccess(status));
  32. }).catch(function (error) {
  33. dispatch(reblogFail(status, error));
  34. });
  35. };
  36. };
  37. export function unreblog(status) {
  38. return (dispatch, getState) => {
  39. dispatch(unreblogRequest(status));
  40. api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
  41. dispatch(importFetchedStatus(response.data));
  42. dispatch(unreblogSuccess(status));
  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. skipLoading: true,
  53. };
  54. };
  55. export function reblogSuccess(status) {
  56. return {
  57. type: REBLOG_SUCCESS,
  58. status: status,
  59. skipLoading: true,
  60. };
  61. };
  62. export function reblogFail(status, error) {
  63. return {
  64. type: REBLOG_FAIL,
  65. status: status,
  66. error: error,
  67. skipLoading: true,
  68. };
  69. };
  70. export function unreblogRequest(status) {
  71. return {
  72. type: UNREBLOG_REQUEST,
  73. status: status,
  74. skipLoading: true,
  75. };
  76. };
  77. export function unreblogSuccess(status) {
  78. return {
  79. type: UNREBLOG_SUCCESS,
  80. status: status,
  81. skipLoading: true,
  82. };
  83. };
  84. export function unreblogFail(status, error) {
  85. return {
  86. type: UNREBLOG_FAIL,
  87. status: status,
  88. error: error,
  89. skipLoading: true,
  90. };
  91. };
  92. export function favourite(status) {
  93. return function (dispatch, getState) {
  94. dispatch(favouriteRequest(status));
  95. api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then(function (response) {
  96. dispatch(importFetchedStatus(response.data));
  97. dispatch(favouriteSuccess(status));
  98. }).catch(function (error) {
  99. dispatch(favouriteFail(status, error));
  100. });
  101. };
  102. };
  103. export function unfavourite(status) {
  104. return (dispatch, getState) => {
  105. dispatch(unfavouriteRequest(status));
  106. api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
  107. dispatch(importFetchedStatus(response.data));
  108. dispatch(unfavouriteSuccess(status));
  109. }).catch(error => {
  110. dispatch(unfavouriteFail(status, error));
  111. });
  112. };
  113. };
  114. export function favouriteRequest(status) {
  115. return {
  116. type: FAVOURITE_REQUEST,
  117. status: status,
  118. skipLoading: true,
  119. };
  120. };
  121. export function favouriteSuccess(status) {
  122. return {
  123. type: FAVOURITE_SUCCESS,
  124. status: status,
  125. skipLoading: true,
  126. };
  127. };
  128. export function favouriteFail(status, error) {
  129. return {
  130. type: FAVOURITE_FAIL,
  131. status: status,
  132. error: error,
  133. skipLoading: true,
  134. };
  135. };
  136. export function unfavouriteRequest(status) {
  137. return {
  138. type: UNFAVOURITE_REQUEST,
  139. status: status,
  140. skipLoading: true,
  141. };
  142. };
  143. export function unfavouriteSuccess(status) {
  144. return {
  145. type: UNFAVOURITE_SUCCESS,
  146. status: status,
  147. skipLoading: true,
  148. };
  149. };
  150. export function unfavouriteFail(status, error) {
  151. return {
  152. type: UNFAVOURITE_FAIL,
  153. status: status,
  154. error: error,
  155. skipLoading: true,
  156. };
  157. };
  158. export function fetchReblogs(id) {
  159. return (dispatch, getState) => {
  160. dispatch(fetchReblogsRequest(id));
  161. api(getState).get(`/api/v1/statuses/${id}/reblogged_by`).then(response => {
  162. dispatch(importFetchedAccounts(response.data));
  163. dispatch(fetchReblogsSuccess(id, response.data));
  164. }).catch(error => {
  165. dispatch(fetchReblogsFail(id, error));
  166. });
  167. };
  168. };
  169. export function fetchReblogsRequest(id) {
  170. return {
  171. type: REBLOGS_FETCH_REQUEST,
  172. id,
  173. };
  174. };
  175. export function fetchReblogsSuccess(id, accounts) {
  176. return {
  177. type: REBLOGS_FETCH_SUCCESS,
  178. id,
  179. accounts,
  180. };
  181. };
  182. export function fetchReblogsFail(id, error) {
  183. return {
  184. type: REBLOGS_FETCH_FAIL,
  185. error,
  186. };
  187. };
  188. export function fetchFavourites(id) {
  189. return (dispatch, getState) => {
  190. dispatch(fetchFavouritesRequest(id));
  191. api(getState).get(`/api/v1/statuses/${id}/favourited_by`).then(response => {
  192. dispatch(importFetchedAccounts(response.data));
  193. dispatch(fetchFavouritesSuccess(id, response.data));
  194. }).catch(error => {
  195. dispatch(fetchFavouritesFail(id, error));
  196. });
  197. };
  198. };
  199. export function fetchFavouritesRequest(id) {
  200. return {
  201. type: FAVOURITES_FETCH_REQUEST,
  202. id,
  203. };
  204. };
  205. export function fetchFavouritesSuccess(id, accounts) {
  206. return {
  207. type: FAVOURITES_FETCH_SUCCESS,
  208. id,
  209. accounts,
  210. };
  211. };
  212. export function fetchFavouritesFail(id, error) {
  213. return {
  214. type: FAVOURITES_FETCH_FAIL,
  215. error,
  216. };
  217. };