sforkowany z mirror/soapbox
Refactor threading, fixes #422
rodzic
d8d6b0c950
commit
b29ed6b18a
|
@ -4,8 +4,7 @@ import {
|
||||||
} from '../actions/accounts';
|
} from '../actions/accounts';
|
||||||
import { CONTEXT_FETCH_SUCCESS } from '../actions/statuses';
|
import { CONTEXT_FETCH_SUCCESS } from '../actions/statuses';
|
||||||
import { TIMELINE_DELETE, TIMELINE_UPDATE } from '../actions/timelines';
|
import { TIMELINE_DELETE, TIMELINE_UPDATE } from '../actions/timelines';
|
||||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
||||||
import compareId from '../compare_id';
|
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
inReplyTos: ImmutableMap(),
|
inReplyTos: ImmutableMap(),
|
||||||
|
@ -16,26 +15,16 @@ const normalizeContext = (immutableState, id, ancestors, descendants) => immutab
|
||||||
state.update('inReplyTos', immutableAncestors => immutableAncestors.withMutations(inReplyTos => {
|
state.update('inReplyTos', immutableAncestors => immutableAncestors.withMutations(inReplyTos => {
|
||||||
state.update('replies', immutableDescendants => immutableDescendants.withMutations(replies => {
|
state.update('replies', immutableDescendants => immutableDescendants.withMutations(replies => {
|
||||||
function addReply({ id, in_reply_to_id }) {
|
function addReply({ id, in_reply_to_id }) {
|
||||||
if (in_reply_to_id && !inReplyTos.has(id)) {
|
if (in_reply_to_id) {
|
||||||
|
replies.update(in_reply_to_id, ImmutableOrderedSet(), siblings => {
|
||||||
replies.update(in_reply_to_id, ImmutableList(), siblings => {
|
return siblings.add(id).sort();
|
||||||
const index = siblings.findLastIndex(sibling => compareId(sibling, id) < 0);
|
|
||||||
return siblings.insert(index + 1, id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
inReplyTos.set(id, in_reply_to_id);
|
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);
|
ancestors.forEach(addReply);
|
||||||
|
|
||||||
if (ancestors[0]) {
|
|
||||||
addReply({ id, in_reply_to_id: ancestors[ancestors.length - 1].id });
|
|
||||||
}
|
|
||||||
|
|
||||||
descendants.forEach(addReply);
|
descendants.forEach(addReply);
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
|
@ -76,12 +65,12 @@ const filterContexts = (state, relationship, statuses) => {
|
||||||
const updateContext = (state, status) => {
|
const updateContext = (state, status) => {
|
||||||
if (status.in_reply_to_id) {
|
if (status.in_reply_to_id) {
|
||||||
return state.withMutations(mutable => {
|
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);
|
mutable.setIn(['inReplyTos', status.id], status.in_reply_to_id);
|
||||||
|
|
||||||
if (!replies.includes(status.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