Timelines: push pending statuses into queue

This commit is contained in:
Alex Gleason 2021-10-23 15:08:21 -05:00
parent d677ef7cdf
commit f290b78636
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -236,17 +236,16 @@ const getTimelinesByVisibility = visibility => {
}
};
const replaceItem = (state, timelineId, oldId, newId) => {
return state.updateIn([timelineId, 'items'], ids => {
const list = ImmutableList(ids);
const index = list.indexOf(oldId);
// Given an OrderedSet of IDs, replace oldId with newId maintaining its position
const replaceId = (ids, oldId, newId) => {
const list = ImmutableList(ids);
const index = list.indexOf(oldId);
if (index > -1) {
return ImmutableOrderedSet(list.set(index, newId));
} else {
return ids;
}
});
if (index > -1) {
return ImmutableOrderedSet(list.set(index, newId));
} else {
return ids;
}
};
const importPendingStatus = (state, params, idempotencyKey) => {
@ -256,7 +255,7 @@ const importPendingStatus = (state, params, idempotencyKey) => {
const timelineIds = getTimelinesByVisibility(params.visibility);
timelineIds.forEach(timelineId => {
updateTimeline(state, timelineId, statusId);
updateTimelineQueue(state, timelineId, statusId);
});
});
};
@ -264,8 +263,12 @@ const importPendingStatus = (state, params, idempotencyKey) => {
const replacePendingStatus = (state, idempotencyKey, newId) => {
const oldId = `末pending-${idempotencyKey}`;
state.keySeq().forEach(timelineId => {
return replaceItem(state, timelineId, oldId, newId);
// Loop through timelines and replace the pending status with the real one
return state.withMutations(state => {
state.keySeq().forEach(timelineId => {
state.updateIn([timelineId, 'items'], ids => replaceId(ids, oldId, newId));
state.updateIn([timelineId, 'queuedItems'], ids => replaceId(ids, oldId, newId));
});
});
};