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.

109 lines
2.7 KiB

  1. import api from '../api'
  2. export const TIMELINE_UPDATE = 'TIMELINE_UPDATE';
  3. export const TIMELINE_DELETE = 'TIMELINE_DELETE';
  4. export const TIMELINE_REFRESH_REQUEST = 'TIMELINE_REFRESH_REQUEST';
  5. export const TIMELINE_REFRESH_SUCCESS = 'TIMELINE_REFRESH_SUCCESS';
  6. export const TIMELINE_REFRESH_FAIL = 'TIMELINE_REFRESH_FAIL';
  7. export const TIMELINE_EXPAND_REQUEST = 'TIMELINE_EXPAND_REQUEST';
  8. export const TIMELINE_EXPAND_SUCCESS = 'TIMELINE_EXPAND_SUCCESS';
  9. export const TIMELINE_EXPAND_FAIL = 'TIMELINE_EXPAND_FAIL';
  10. export function refreshTimelineSuccess(timeline, statuses, replace) {
  11. return {
  12. type: TIMELINE_REFRESH_SUCCESS,
  13. timeline: timeline,
  14. statuses: statuses,
  15. replace: replace
  16. };
  17. };
  18. export function updateTimeline(timeline, status) {
  19. return {
  20. type: TIMELINE_UPDATE,
  21. timeline: timeline,
  22. status: status
  23. };
  24. };
  25. export function deleteFromTimelines(id) {
  26. return {
  27. type: TIMELINE_DELETE,
  28. id: id
  29. };
  30. };
  31. export function refreshTimelineRequest(timeline) {
  32. return {
  33. type: TIMELINE_REFRESH_REQUEST,
  34. timeline: timeline
  35. };
  36. };
  37. export function refreshTimeline(timeline, replace = false) {
  38. return function (dispatch, getState) {
  39. dispatch(refreshTimelineRequest(timeline));
  40. const ids = getState().getIn(['timelines', timeline]);
  41. const newestId = ids.size > 0 ? ids.first() : null;
  42. let params = '';
  43. if (newestId !== null && !replace) {
  44. params = `?since_id=${newestId}`;
  45. }
  46. api(getState).get(`/api/v1/statuses/${timeline}${params}`).then(function (response) {
  47. dispatch(refreshTimelineSuccess(timeline, response.data, replace));
  48. }).catch(function (error) {
  49. dispatch(refreshTimelineFail(timeline, error));
  50. });
  51. };
  52. };
  53. export function refreshTimelineFail(timeline, error) {
  54. return {
  55. type: TIMELINE_REFRESH_FAIL,
  56. timeline: timeline,
  57. error: error
  58. };
  59. };
  60. export function expandTimeline(timeline) {
  61. return (dispatch, getState) => {
  62. const lastId = getState().getIn(['timelines', timeline]).last();
  63. dispatch(expandTimelineRequest(timeline));
  64. api(getState).get(`/api/v1/statuses/${timeline}?max_id=${lastId}`).then(response => {
  65. dispatch(expandTimelineSuccess(timeline, response.data));
  66. }).catch(error => {
  67. dispatch(expandTimelineFail(timeline, error));
  68. });
  69. };
  70. };
  71. export function expandTimelineRequest(timeline) {
  72. return {
  73. type: TIMELINE_EXPAND_REQUEST,
  74. timeline: timeline
  75. };
  76. };
  77. export function expandTimelineSuccess(timeline, statuses) {
  78. return {
  79. type: TIMELINE_EXPAND_SUCCESS,
  80. timeline: timeline,
  81. statuses: statuses
  82. };
  83. };
  84. export function expandTimelineFail(timeline, error) {
  85. return {
  86. type: TIMELINE_EXPAND_FAIL,
  87. timeline: timeline,
  88. error: error
  89. };
  90. };