Decrement reply count when removing a status.
This commit is contained in:
parent
8304f25577
commit
8847b3cc03
4 changed files with 10 additions and 4 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -28,6 +28,8 @@ import {
|
||||||
STATUS_UNMUTE_SUCCESS,
|
STATUS_UNMUTE_SUCCESS,
|
||||||
STATUS_REVEAL,
|
STATUS_REVEAL,
|
||||||
STATUS_HIDE,
|
STATUS_HIDE,
|
||||||
|
STATUS_DELETE_REQUEST,
|
||||||
|
STATUS_DELETE_FAIL,
|
||||||
} from '../actions/statuses';
|
} from '../actions/statuses';
|
||||||
import { TIMELINE_DELETE } from '../actions/timelines';
|
import { TIMELINE_DELETE } from '../actions/timelines';
|
||||||
|
|
||||||
|
@ -152,7 +154,7 @@ const deleteStatus = (state: State, id: string, references: Array<string>) => {
|
||||||
return state.delete(id);
|
return state.delete(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const importPendingStatus = (state: State, { in_reply_to_id }: APIEntity) => {
|
const incrementReplyCount = (state: State, { in_reply_to_id }: APIEntity) => {
|
||||||
if (in_reply_to_id) {
|
if (in_reply_to_id) {
|
||||||
return state.updateIn([in_reply_to_id, 'replies_count'], 0, count => {
|
return state.updateIn([in_reply_to_id, 'replies_count'], 0, count => {
|
||||||
return typeof count === 'number' ? count + 1 : 0;
|
return typeof count === 'number' ? count + 1 : 0;
|
||||||
|
@ -162,7 +164,7 @@ const importPendingStatus = (state: State, { in_reply_to_id }: APIEntity) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deletePendingStatus = (state: State, { in_reply_to_id }: APIEntity) => {
|
const decrementReplyCount = (state: State, { in_reply_to_id }: APIEntity) => {
|
||||||
if (in_reply_to_id) {
|
if (in_reply_to_id) {
|
||||||
return state.updateIn([in_reply_to_id, 'replies_count'], 0, count => {
|
return state.updateIn([in_reply_to_id, 'replies_count'], 0, count => {
|
||||||
return typeof count === 'number' ? Math.max(0, count - 1) : 0;
|
return typeof count === 'number' ? Math.max(0, count - 1) : 0;
|
||||||
|
@ -200,9 +202,9 @@ export default function statuses(state = initialState, action: AnyAction): State
|
||||||
case STATUSES_IMPORT:
|
case STATUSES_IMPORT:
|
||||||
return importStatuses(state, action.statuses, action.expandSpoilers);
|
return importStatuses(state, action.statuses, action.expandSpoilers);
|
||||||
case STATUS_CREATE_REQUEST:
|
case STATUS_CREATE_REQUEST:
|
||||||
return importPendingStatus(state, action.params);
|
return incrementReplyCount(state, action.params);
|
||||||
case STATUS_CREATE_FAIL:
|
case STATUS_CREATE_FAIL:
|
||||||
return deletePendingStatus(state, action.params);
|
return decrementReplyCount(state, action.params);
|
||||||
case FAVOURITE_REQUEST:
|
case FAVOURITE_REQUEST:
|
||||||
return simulateFavourite(state, action.status.id, true);
|
return simulateFavourite(state, action.status.id, true);
|
||||||
case UNFAVOURITE_REQUEST:
|
case UNFAVOURITE_REQUEST:
|
||||||
|
@ -249,6 +251,10 @@ export default function statuses(state = initialState, action: AnyAction): State
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
case STATUS_DELETE_REQUEST:
|
||||||
|
return decrementReplyCount(state, action.params);
|
||||||
|
case STATUS_DELETE_FAIL:
|
||||||
|
return incrementReplyCount(state, action.params);
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
return deleteStatus(state, action.id, action.references);
|
return deleteStatus(state, action.id, action.references);
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue