From cc6d2599cba1906c1a119579ee8ab639787d04cb Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 21 Apr 2021 18:14:20 -0500 Subject: [PATCH] Wholistic context import (builds tree from anywhere in the thread) --- app/soapbox/reducers/contexts.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/soapbox/reducers/contexts.js b/app/soapbox/reducers/contexts.js index 703e911b7..cff3636eb 100644 --- a/app/soapbox/reducers/contexts.js +++ b/app/soapbox/reducers/contexts.js @@ -38,16 +38,23 @@ const insertTombstone = (state, ancestorId, descendantId) => { }); }; -const normalizeContext = (state, id, ancestors, descendants) => state.withMutations(state => { - importStatuses(state, ancestors); +const importBranch = (state, statuses, rootId) => { + return state.withMutations(state => { + statuses.forEach((status, i) => { + const lastId = rootId && i === 0 ? rootId : (statuses[i - 1] || {}).id; - descendants.forEach(status => { - if (status.in_reply_to_id) { - importStatus(state, status); - } else { - insertTombstone(state, id, status.id); - } + if (status.in_reply_to_id) { + importStatus(state, status); + } else if (lastId) { + insertTombstone(state, lastId, status.id); + } + }); }); +}; + +const normalizeContext = (state, id, ancestors, descendants) => state.withMutations(state => { + importBranch(state, ancestors); + importBranch(state, descendants, id); if (ancestors.length > 0 && !state.getIn(['inReplyTos', id])) { insertTombstone(state, ancestors[ancestors.length - 1].id, id);