kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Refactor threading, fixes #422
rodzic
d8d6b0c950
commit
b29ed6b18a
|
@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue