kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Contexts: check for cyclical in_reply_tos and prevent stitching them with tombstones
rodzic
b76bb097f2
commit
b528c4aa63
|
@ -39,7 +39,25 @@ const importStatuses = (state, statuses) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isReplyTo = (state, childId, parentId, initialId = null) => {
|
||||||
|
if (!childId) return false;
|
||||||
|
|
||||||
|
// Prevent cycles
|
||||||
|
if (childId === initialId) return false;
|
||||||
|
initialId = initialId || childId;
|
||||||
|
|
||||||
|
if (childId === parentId) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
const nextId = state.getIn(['inReplyTos', childId]);
|
||||||
|
return isReplyTo(state, nextId, parentId, initialId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const insertTombstone = (state, ancestorId, descendantId) => {
|
const insertTombstone = (state, ancestorId, descendantId) => {
|
||||||
|
// Prevent infinite loop if the API returns a bogus response
|
||||||
|
if (isReplyTo(state, ancestorId, descendantId)) return state;
|
||||||
|
|
||||||
const tombstoneId = `${descendantId}-tombstone`;
|
const tombstoneId = `${descendantId}-tombstone`;
|
||||||
return state.withMutations(state => {
|
return state.withMutations(state => {
|
||||||
importStatus(state, { id: tombstoneId, in_reply_to_id: ancestorId });
|
importStatus(state, { id: tombstoneId, in_reply_to_id: ancestorId });
|
||||||
|
|
Ładowanie…
Reference in New Issue