logo

mastofe

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

statuses.js (1999B)


  1. import {
  2. REBLOG_REQUEST,
  3. REBLOG_FAIL,
  4. FAVOURITE_REQUEST,
  5. FAVOURITE_FAIL,
  6. } from '../actions/interactions';
  7. import {
  8. STATUS_MUTE_SUCCESS,
  9. STATUS_UNMUTE_SUCCESS,
  10. STATUS_REVEAL,
  11. STATUS_HIDE,
  12. } from '../actions/statuses';
  13. import { TIMELINE_DELETE } from '../actions/timelines';
  14. import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
  15. import { Map as ImmutableMap, fromJS } from 'immutable';
  16. const importStatus = (state, status) => state.set(status.id, fromJS(status));
  17. const importStatuses = (state, statuses) =>
  18. state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status)));
  19. const deleteStatus = (state, id, references) => {
  20. references.forEach(ref => {
  21. state = deleteStatus(state, ref[0], []);
  22. });
  23. return state.delete(id);
  24. };
  25. const initialState = ImmutableMap();
  26. export default function statuses(state = initialState, action) {
  27. switch(action.type) {
  28. case STATUS_IMPORT:
  29. return importStatus(state, action.status);
  30. case STATUSES_IMPORT:
  31. return importStatuses(state, action.statuses);
  32. case FAVOURITE_REQUEST:
  33. return state.setIn([action.status.get('id'), 'favourited'], true);
  34. case FAVOURITE_FAIL:
  35. return state.setIn([action.status.get('id'), 'favourited'], false);
  36. case REBLOG_REQUEST:
  37. return state.setIn([action.status.get('id'), 'reblogged'], true);
  38. case REBLOG_FAIL:
  39. return state.setIn([action.status.get('id'), 'reblogged'], false);
  40. case STATUS_MUTE_SUCCESS:
  41. return state.setIn([action.id, 'muted'], true);
  42. case STATUS_UNMUTE_SUCCESS:
  43. return state.setIn([action.id, 'muted'], false);
  44. case STATUS_REVEAL:
  45. return state.withMutations(map => {
  46. action.ids.forEach(id => map.setIn([id, 'hidden'], false));
  47. });
  48. case STATUS_HIDE:
  49. return state.withMutations(map => {
  50. action.ids.forEach(id => map.setIn([id, 'hidden'], true));
  51. });
  52. case TIMELINE_DELETE:
  53. return deleteStatus(state, action.id, action.references);
  54. default:
  55. return state;
  56. }
  57. };