From b29ed6b18a5ca64f70c86f31e6c22ef0ff605ef7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 18 Sep 2020 16:16:56 -0500 Subject: [PATCH] Refactor threading, fixes #422 --- app/soapbox/reducers/contexts.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/soapbox/reducers/contexts.js b/app/soapbox/reducers/contexts.js index 4c2d6cc8a..8df462f81 100644 --- a/app/soapbox/reducers/contexts.js +++ b/app/soapbox/reducers/contexts.js @@ -4,8 +4,7 @@ import { } from '../actions/accounts'; import { CONTEXT_FETCH_SUCCESS } from '../actions/statuses'; import { TIMELINE_DELETE, TIMELINE_UPDATE } from '../actions/timelines'; -import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; -import compareId from '../compare_id'; +import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable'; const initialState = ImmutableMap({ inReplyTos: ImmutableMap(), @@ -16,26 +15,16 @@ const normalizeContext = (immutableState, id, ancestors, descendants) => immutab state.update('inReplyTos', immutableAncestors => immutableAncestors.withMutations(inReplyTos => { state.update('replies', immutableDescendants => immutableDescendants.withMutations(replies => { function addReply({ id, in_reply_to_id }) { - if (in_reply_to_id && !inReplyTos.has(id)) { - - replies.update(in_reply_to_id, ImmutableList(), siblings => { - const index = siblings.findLastIndex(sibling => compareId(sibling, id) < 0); - return siblings.insert(index + 1, id); + if (in_reply_to_id) { + replies.update(in_reply_to_id, ImmutableOrderedSet(), siblings => { + return siblings.add(id).sort(); }); inReplyTos.set(id, in_reply_to_id); } } - // We know in_reply_to_id of statuses but `id` itself. - // So we assume that the status of the id replies to last ancestors. - ancestors.forEach(addReply); - - if (ancestors[0]) { - addReply({ id, in_reply_to_id: ancestors[ancestors.length - 1].id }); - } - descendants.forEach(addReply); })); })); @@ -76,12 +65,12 @@ const filterContexts = (state, relationship, statuses) => { const updateContext = (state, status) => { if (status.in_reply_to_id) { return state.withMutations(mutable => { - const replies = mutable.getIn(['replies', status.in_reply_to_id], ImmutableList()); + const replies = mutable.getIn(['replies', status.in_reply_to_id], ImmutableOrderedSet()); mutable.setIn(['inReplyTos', status.id], status.in_reply_to_id); if (!replies.includes(status.id)) { - mutable.setIn(['replies', status.in_reply_to_id], replies.push(status.id)); + mutable.setIn(['replies', status.in_reply_to_id], replies.add(status.id).sort()); } }); }