2017-02-14 14:59:26 -05:00
|
|
|
import {
|
|
|
|
REPORT_INIT,
|
|
|
|
REPORT_SUBMIT_REQUEST,
|
|
|
|
REPORT_SUBMIT_SUCCESS,
|
|
|
|
REPORT_SUBMIT_FAIL,
|
|
|
|
REPORT_CANCEL,
|
2017-04-13 13:36:41 -04:00
|
|
|
REPORT_STATUS_TOGGLE,
|
2017-05-20 11:31:47 -04:00
|
|
|
REPORT_COMMENT_CHANGE,
|
2018-03-12 14:06:28 -04:00
|
|
|
REPORT_FORWARD_CHANGE,
|
2017-12-04 02:26:40 -05:00
|
|
|
} from 'flavours/glitch/actions/reports';
|
2019-07-10 13:12:51 -04:00
|
|
|
import {
|
|
|
|
TIMELINE_DELETE,
|
|
|
|
} from 'flavours/glitch/actions/timelines';
|
2017-07-10 19:00:14 -04:00
|
|
|
import { Map as ImmutableMap, Set as ImmutableSet } from 'immutable';
|
2017-02-14 14:59:26 -05:00
|
|
|
|
2017-07-10 19:00:14 -04:00
|
|
|
const initialState = ImmutableMap({
|
|
|
|
new: ImmutableMap({
|
2017-02-14 14:59:26 -05:00
|
|
|
isSubmitting: false,
|
|
|
|
account_id: null,
|
2017-07-10 19:00:14 -04:00
|
|
|
status_ids: ImmutableSet(),
|
2017-05-20 11:31:47 -04:00
|
|
|
comment: '',
|
2018-03-12 14:06:28 -04:00
|
|
|
forward: false,
|
2017-05-20 11:31:47 -04:00
|
|
|
}),
|
2017-02-14 14:59:26 -05:00
|
|
|
});
|
|
|
|
|
2019-07-10 13:12:51 -04:00
|
|
|
const deleteStatus = (state, id, references) => {
|
|
|
|
references.forEach(ref => {
|
|
|
|
state = deleteStatus(state, ref[0], []);
|
|
|
|
});
|
|
|
|
|
|
|
|
return state.updateIn(['new', 'status_ids'], ImmutableSet(), set => set.remove(id));
|
|
|
|
};
|
|
|
|
|
2017-02-14 14:59:26 -05:00
|
|
|
export default function reports(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case REPORT_INIT:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.setIn(['new', 'isSubmitting'], false);
|
|
|
|
map.setIn(['new', 'account_id'], action.account.get('id'));
|
|
|
|
|
|
|
|
if (state.getIn(['new', 'account_id']) !== action.account.get('id')) {
|
2017-07-10 19:00:14 -04:00
|
|
|
map.setIn(['new', 'status_ids'], action.status ? ImmutableSet([action.status.getIn(['reblog', 'id'], action.status.get('id'))]) : ImmutableSet());
|
2017-02-14 14:59:26 -05:00
|
|
|
map.setIn(['new', 'comment'], '');
|
2017-09-09 07:42:48 -04:00
|
|
|
} else if (action.status) {
|
2017-07-10 19:00:14 -04:00
|
|
|
map.updateIn(['new', 'status_ids'], ImmutableSet(), set => set.add(action.status.getIn(['reblog', 'id'], action.status.get('id'))));
|
2017-02-14 14:59:26 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
case REPORT_STATUS_TOGGLE:
|
2017-07-10 19:00:14 -04:00
|
|
|
return state.updateIn(['new', 'status_ids'], ImmutableSet(), set => {
|
2017-02-14 14:59:26 -05:00
|
|
|
if (action.checked) {
|
|
|
|
return set.add(action.statusId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return set.remove(action.statusId);
|
|
|
|
});
|
2017-04-13 13:36:41 -04:00
|
|
|
case REPORT_COMMENT_CHANGE:
|
|
|
|
return state.setIn(['new', 'comment'], action.comment);
|
2018-03-12 14:06:28 -04:00
|
|
|
case REPORT_FORWARD_CHANGE:
|
|
|
|
return state.setIn(['new', 'forward'], action.forward);
|
2017-02-14 14:59:26 -05:00
|
|
|
case REPORT_SUBMIT_REQUEST:
|
|
|
|
return state.setIn(['new', 'isSubmitting'], true);
|
|
|
|
case REPORT_SUBMIT_FAIL:
|
|
|
|
return state.setIn(['new', 'isSubmitting'], false);
|
|
|
|
case REPORT_CANCEL:
|
|
|
|
case REPORT_SUBMIT_SUCCESS:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.setIn(['new', 'account_id'], null);
|
2017-07-10 19:00:14 -04:00
|
|
|
map.setIn(['new', 'status_ids'], ImmutableSet());
|
2017-02-14 14:59:26 -05:00
|
|
|
map.setIn(['new', 'comment'], '');
|
|
|
|
map.setIn(['new', 'isSubmitting'], false);
|
|
|
|
});
|
2019-07-10 13:12:51 -04:00
|
|
|
case TIMELINE_DELETE:
|
|
|
|
return deleteStatus(state, action.id, action.references);
|
2017-02-14 14:59:26 -05:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|