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.

31 lines
1.0 KiB

  1. import { TIMELINE_SET, TIMELINE_UPDATE } from '../actions/timelines';
  2. import { REBLOG_SUCCESS, FAVOURITE_SUCCESS } from '../actions/interactions';
  3. import Immutable from 'immutable';
  4. const initialState = Immutable.Map();
  5. function updateMatchingStatuses(state, needle, callback) {
  6. return state.map(function (list) {
  7. return list.map(function (status) {
  8. if (status.get('id') === needle.get('id')) {
  9. return callback(status);
  10. }
  11. return status;
  12. });
  13. });
  14. };
  15. export default function timelines(state = initialState, action) {
  16. switch(action.type) {
  17. case TIMELINE_SET:
  18. return state.set(action.timeline, Immutable.fromJS(action.statuses));
  19. case TIMELINE_UPDATE:
  20. return state.update(action.timeline, list => list.unshift(Immutable.fromJS(action.status)));
  21. case REBLOG_SUCCESS:
  22. case FAVOURITE_SUCCESS:
  23. return updateMatchingStatuses(state, action.status, () => Immutable.fromJS(action.response));
  24. default:
  25. return state;
  26. }
  27. }