Contexts: check for cyclical in_reply_tos and prevent stitching them with tombstones

merge-requests/889/head
Alex Gleason 2021-11-23 15:17:12 -06:00
rodzic b76bb097f2
commit b528c4aa63
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 18 dodań i 0 usunięć

Wyświetl plik

@ -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) => {
// Prevent infinite loop if the API returns a bogus response
if (isReplyTo(state, ancestorId, descendantId)) return state;
const tombstoneId = `${descendantId}-tombstone`;
return state.withMutations(state => {
importStatus(state, { id: tombstoneId, in_reply_to_id: ancestorId });