闭社主体 forked from https://github.com/tootsuite/mastodon
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.

159 lines
3.7 KiB

8 years ago
  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 function reblog(status) {
  15. return function (dispatch, getState) {
  16. dispatch(reblogRequest(status));
  17. api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then(function (response) {
  18. // The reblog API method returns a new status wrapped around the original. In this case we are only
  19. // interested in how the original is modified, hence passing it skipping the wrapper
  20. dispatch(reblogSuccess(status, response.data.reblog));
  21. }).catch(function (error) {
  22. dispatch(reblogFail(status, error));
  23. });
  24. };
  25. };
  26. export function unreblog(status) {
  27. return (dispatch, getState) => {
  28. dispatch(unreblogRequest(status));
  29. api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
  30. dispatch(unreblogSuccess(status, response.data));
  31. }).catch(error => {
  32. dispatch(unreblogFail(status, error));
  33. });
  34. };
  35. };
  36. export function reblogRequest(status) {
  37. return {
  38. type: REBLOG_REQUEST,
  39. status: status
  40. };
  41. };
  42. export function reblogSuccess(status, response) {
  43. return {
  44. type: REBLOG_SUCCESS,
  45. status: status,
  46. response: response
  47. };
  48. };
  49. export function reblogFail(status, error) {
  50. return {
  51. type: REBLOG_FAIL,
  52. status: status,
  53. error: error
  54. };
  55. };
  56. export function unreblogRequest(status) {
  57. return {
  58. type: UNREBLOG_REQUEST,
  59. status: status
  60. };
  61. };
  62. export function unreblogSuccess(status, response) {
  63. return {
  64. type: UNREBLOG_SUCCESS,
  65. status: status,
  66. response: response
  67. };
  68. };
  69. export function unreblogFail(status, error) {
  70. return {
  71. type: UNREBLOG_FAIL,
  72. status: status,
  73. error: error
  74. };
  75. };
  76. export function favourite(status) {
  77. return function (dispatch, getState) {
  78. dispatch(favouriteRequest(status));
  79. api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then(function (response) {
  80. dispatch(favouriteSuccess(status, response.data));
  81. }).catch(function (error) {
  82. dispatch(favouriteFail(status, error));
  83. });
  84. };
  85. };
  86. export function unfavourite(status) {
  87. return (dispatch, getState) => {
  88. dispatch(unfavouriteRequest(status));
  89. api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
  90. dispatch(unfavouriteSuccess(status, response.data));
  91. }).catch(error => {
  92. dispatch(unfavouriteFail(status, error));
  93. });
  94. };
  95. };
  96. export function favouriteRequest(status) {
  97. return {
  98. type: FAVOURITE_REQUEST,
  99. status: status
  100. };
  101. };
  102. export function favouriteSuccess(status, response) {
  103. return {
  104. type: FAVOURITE_SUCCESS,
  105. status: status,
  106. response: response
  107. };
  108. };
  109. export function favouriteFail(status, error) {
  110. return {
  111. type: FAVOURITE_FAIL,
  112. status: status,
  113. error: error
  114. };
  115. };
  116. export function unfavouriteRequest(status) {
  117. return {
  118. type: UNFAVOURITE_REQUEST,
  119. status: status
  120. };
  121. };
  122. export function unfavouriteSuccess(status, response) {
  123. return {
  124. type: UNFAVOURITE_SUCCESS,
  125. status: status,
  126. response: response
  127. };
  128. };
  129. export function unfavouriteFail(status, error) {
  130. return {
  131. type: UNFAVOURITE_FAIL,
  132. status: status,
  133. error: error
  134. };
  135. };