2019-07-02 08:10:25 +01:00
|
|
|
import {
|
2020-03-14 17:31:29 +00:00
|
|
|
REPOST_REQUEST,
|
|
|
|
REPOST_FAIL,
|
2020-03-02 22:26:25 +00:00
|
|
|
FAVORITE_REQUEST,
|
|
|
|
FAVORITE_FAIL,
|
2020-03-13 18:44:44 +00:00
|
|
|
UNFAVORITE_REQUEST,
|
2019-07-02 08:10:25 +01:00
|
|
|
} from '../actions/interactions';
|
|
|
|
import {
|
|
|
|
STATUS_MUTE_SUCCESS,
|
|
|
|
STATUS_UNMUTE_SUCCESS,
|
|
|
|
STATUS_REVEAL,
|
|
|
|
STATUS_HIDE,
|
|
|
|
} from '../actions/statuses';
|
|
|
|
import { TIMELINE_DELETE } from '../actions/timelines';
|
|
|
|
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
|
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
|
|
|
|
|
|
const importStatus = (state, status) => state.set(status.id, fromJS(status));
|
|
|
|
|
|
|
|
const importStatuses = (state, statuses) =>
|
|
|
|
state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status)));
|
|
|
|
|
|
|
|
const deleteStatus = (state, id, references) => {
|
|
|
|
references.forEach(ref => {
|
|
|
|
state = deleteStatus(state, ref[0], []);
|
|
|
|
});
|
|
|
|
|
|
|
|
return state.delete(id);
|
|
|
|
};
|
|
|
|
|
|
|
|
const initialState = ImmutableMap();
|
|
|
|
|
|
|
|
export default function statuses(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case STATUS_IMPORT:
|
|
|
|
return importStatus(state, action.status);
|
|
|
|
case STATUSES_IMPORT:
|
|
|
|
return importStatuses(state, action.statuses);
|
2020-03-02 22:26:25 +00:00
|
|
|
case FAVORITE_REQUEST:
|
2019-07-02 08:10:25 +01:00
|
|
|
return state.setIn([action.status.get('id'), 'favourited'], true);
|
2020-03-02 22:26:25 +00:00
|
|
|
case FAVORITE_FAIL:
|
2019-07-02 08:10:25 +01:00
|
|
|
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false);
|
2020-03-13 18:44:44 +00:00
|
|
|
case UNFAVORITE_REQUEST:
|
|
|
|
return state.setIn([action.status.get('id'), 'favourited'], false);
|
2020-03-14 17:31:29 +00:00
|
|
|
case REPOST_REQUEST:
|
2019-07-02 08:10:25 +01:00
|
|
|
return state.setIn([action.status.get('id'), 'reblogged'], true);
|
2020-03-14 17:31:29 +00:00
|
|
|
case REPOST_FAIL:
|
2019-07-02 08:10:25 +01:00
|
|
|
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'reblogged'], false);
|
|
|
|
case STATUS_MUTE_SUCCESS:
|
|
|
|
return state.setIn([action.id, 'muted'], true);
|
|
|
|
case STATUS_UNMUTE_SUCCESS:
|
|
|
|
return state.setIn([action.id, 'muted'], false);
|
|
|
|
case STATUS_REVEAL:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
action.ids.forEach(id => {
|
|
|
|
if (!(state.get(id) === undefined)) {
|
|
|
|
map.setIn([id, 'hidden'], false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
case STATUS_HIDE:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
action.ids.forEach(id => {
|
|
|
|
if (!(state.get(id) === undefined)) {
|
|
|
|
map.setIn([id, 'hidden'], true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
case TIMELINE_DELETE:
|
|
|
|
return deleteStatus(state, action.id, action.references);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|