|
|
@ -1,3 +1,7 @@ |
|
|
|
|
|
|
|
import { |
|
|
|
|
|
|
|
ACCOUNT_BLOCK_SUCCESS, |
|
|
|
|
|
|
|
ACCOUNT_MUTE_SUCCESS, |
|
|
|
|
|
|
|
} from 'flavours/glitch/actions/accounts'; |
|
|
|
import { CONTEXT_FETCH_SUCCESS } from 'flavours/glitch/actions/statuses'; |
|
|
|
import { CONTEXT_FETCH_SUCCESS } from 'flavours/glitch/actions/statuses'; |
|
|
|
import { TIMELINE_DELETE, TIMELINE_CONTEXT_UPDATE } from 'flavours/glitch/actions/timelines'; |
|
|
|
import { TIMELINE_DELETE, TIMELINE_CONTEXT_UPDATE } from 'flavours/glitch/actions/timelines'; |
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; |
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; |
|
|
@ -17,18 +21,30 @@ const normalizeContext = (state, id, ancestors, descendants) => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const deleteFromContexts = (state, id) => { |
|
|
|
const deleteFromContexts = (immutableState, ids) => immutableState.withMutations(state => { |
|
|
|
state.getIn(['descendants', id], ImmutableList()).forEach(descendantId => { |
|
|
|
state.update('ancestors', immutableAncestors => immutableAncestors.withMutations(ancestors => { |
|
|
|
state = state.updateIn(['ancestors', descendantId], ImmutableList(), list => list.filterNot(itemId => itemId === id)); |
|
|
|
state.update('descendants', immutableDescendants => immutableDescendants.withMutations(descendants => { |
|
|
|
}); |
|
|
|
ids.forEach(id => { |
|
|
|
|
|
|
|
descendants.get(id, ImmutableList()).forEach(descendantId => { |
|
|
|
|
|
|
|
ancestors.update(descendantId, ImmutableList(), list => list.filterNot(itemId => itemId === id)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
state.getIn(['ancestors', id], ImmutableList()).forEach(ancestorId => { |
|
|
|
ancestors.get(id, ImmutableList()).forEach(ancestorId => { |
|
|
|
state = state.updateIn(['descendants', ancestorId], ImmutableList(), list => list.filterNot(itemId => itemId === id)); |
|
|
|
descendants.update(ancestorId, ImmutableList(), list => list.filterNot(itemId => itemId === id)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
descendants.delete(id); |
|
|
|
|
|
|
|
ancestors.delete(id); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
state = state.deleteIn(['descendants', id]).deleteIn(['ancestors', id]); |
|
|
|
const filterContexts = (state, relationship, statuses) => { |
|
|
|
|
|
|
|
const ownedStatusIds = statuses.filter(status => status.get('account') === relationship.id) |
|
|
|
|
|
|
|
.map(status => status.get('id')); |
|
|
|
|
|
|
|
|
|
|
|
return state; |
|
|
|
return deleteFromContexts(state, ownedStatusIds); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const updateContext = (state, status, references) => { |
|
|
|
const updateContext = (state, status, references) => { |
|
|
@ -49,10 +65,13 @@ const updateContext = (state, status, references) => { |
|
|
|
|
|
|
|
|
|
|
|
export default function contexts(state = initialState, action) { |
|
|
|
export default function contexts(state = initialState, action) { |
|
|
|
switch(action.type) { |
|
|
|
switch(action.type) { |
|
|
|
|
|
|
|
case ACCOUNT_BLOCK_SUCCESS: |
|
|
|
|
|
|
|
case ACCOUNT_MUTE_SUCCESS: |
|
|
|
|
|
|
|
return filterContexts(state, action.relationship, action.statuses); |
|
|
|
case CONTEXT_FETCH_SUCCESS: |
|
|
|
case CONTEXT_FETCH_SUCCESS: |
|
|
|
return normalizeContext(state, action.id, action.ancestors, action.descendants); |
|
|
|
return normalizeContext(state, action.id, action.ancestors, action.descendants); |
|
|
|
case TIMELINE_DELETE: |
|
|
|
case TIMELINE_DELETE: |
|
|
|
return deleteFromContexts(state, action.id); |
|
|
|
return deleteFromContexts(state, [action.id]); |
|
|
|
case TIMELINE_CONTEXT_UPDATE: |
|
|
|
case TIMELINE_CONTEXT_UPDATE: |
|
|
|
return updateContext(state, action.status, action.references); |
|
|
|
return updateContext(state, action.status, action.references); |
|
|
|
default: |
|
|
|
default: |
|
|
|