2021-06-27 12:58:40 -07:00
|
|
|
import { STATUS_CREATE_SUCCESS } from 'soapbox/actions/statuses';
|
2021-06-27 15:04:23 -07:00
|
|
|
import {
|
|
|
|
SCHEDULED_STATUSES_FETCH_SUCCESS,
|
|
|
|
SCHEDULED_STATUS_CANCEL_REQUEST,
|
|
|
|
SCHEDULED_STATUS_CANCEL_SUCCESS,
|
|
|
|
} from 'soapbox/actions/scheduled_statuses';
|
2021-06-27 12:58:40 -07:00
|
|
|
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
|
2021-06-27 11:59:10 -07:00
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
|
|
|
2021-06-27 12:58:40 -07:00
|
|
|
const importStatus = (state, status) => {
|
|
|
|
if (!status.scheduled_at) return state;
|
|
|
|
return state.set(status.id, fromJS(status));
|
|
|
|
};
|
2021-06-27 11:59:10 -07:00
|
|
|
|
|
|
|
const importStatuses = (state, statuses) =>
|
|
|
|
state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status)));
|
|
|
|
|
2021-06-27 15:04:23 -07:00
|
|
|
const deleteStatus = (state, id) => state.delete(id);
|
|
|
|
|
2021-06-27 11:59:10 -07:00
|
|
|
const initialState = ImmutableMap();
|
|
|
|
|
2021-10-09 14:56:03 -07:00
|
|
|
export default function scheduled_statuses(state = initialState, action) {
|
2021-06-27 11:59:10 -07:00
|
|
|
switch(action.type) {
|
|
|
|
case STATUS_IMPORT:
|
2021-06-27 12:58:40 -07:00
|
|
|
case STATUS_CREATE_SUCCESS:
|
2021-06-27 11:59:10 -07:00
|
|
|
return importStatus(state, action.status);
|
|
|
|
case STATUSES_IMPORT:
|
2021-06-27 15:04:23 -07:00
|
|
|
case SCHEDULED_STATUSES_FETCH_SUCCESS:
|
2021-06-27 11:59:10 -07:00
|
|
|
return importStatuses(state, action.statuses);
|
2021-06-27 15:04:23 -07:00
|
|
|
case SCHEDULED_STATUS_CANCEL_REQUEST:
|
|
|
|
case SCHEDULED_STATUS_CANCEL_SUCCESS:
|
|
|
|
return deleteStatus(state, action.id);
|
2021-06-27 11:59:10 -07:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|