Fix paginated comments, improve Mastodon tombstones
This commit is contained in:
parent
d19a2d973f
commit
02726cfcc3
|
@ -179,10 +179,18 @@ export function fetchContext(id) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchNext(next) {
|
export function fetchNext(statusId, next) {
|
||||||
return async(dispatch, getState) => {
|
return async(dispatch, getState) => {
|
||||||
const response = await api(getState).get(next);
|
const response = await api(getState).get(next);
|
||||||
dispatch(importFetchedStatuses(response.data));
|
dispatch(importFetchedStatuses(response.data));
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: CONTEXT_FETCH_SUCCESS,
|
||||||
|
id: statusId,
|
||||||
|
ancestors: [],
|
||||||
|
descendants: response.data,
|
||||||
|
});
|
||||||
|
|
||||||
return { next: getNextLink(response) };
|
return { next: getNextLink(response) };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -213,6 +221,14 @@ export function fetchStatusWithContext(id) {
|
||||||
dispatch(fetchDescendants(id)),
|
dispatch(fetchDescendants(id)),
|
||||||
dispatch(fetchStatus(id)),
|
dispatch(fetchStatus(id)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: CONTEXT_FETCH_SUCCESS,
|
||||||
|
id,
|
||||||
|
ancestors: responses[0].data,
|
||||||
|
descendants: responses[1].data,
|
||||||
|
});
|
||||||
|
|
||||||
const next = getNextLink(responses[1]);
|
const next = getNextLink(responses[1]);
|
||||||
return { next };
|
return { next };
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -654,10 +654,11 @@ class Status extends ImmutablePureComponent<IStatus, IStatusState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLoadMore = () => {
|
handleLoadMore = () => {
|
||||||
|
const { status } = this.props;
|
||||||
const { next } = this.state;
|
const { next } = this.state;
|
||||||
|
|
||||||
if (next) {
|
if (next) {
|
||||||
this.props.dispatch(fetchNext(next)).then(({ next }) => {
|
this.props.dispatch(fetchNext(status.id, next)).then(({ next }) => {
|
||||||
this.setState({ next });
|
this.setState({ next });
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,15 +67,41 @@ const insertTombstone = (state, ancestorId, descendantId) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const importBranch = (state, statuses, rootId) => {
|
/** Find the highest level status from this statusId. */
|
||||||
|
const getRootNode = (state, statusId, initialId = statusId) => {
|
||||||
|
const parent = state.getIn(['inReplyTos', statusId]);
|
||||||
|
|
||||||
|
if (!parent) {
|
||||||
|
return statusId;
|
||||||
|
} else if (parent === initialId) {
|
||||||
|
// Prevent cycles
|
||||||
|
return parent;
|
||||||
|
} else {
|
||||||
|
return getRootNode(state, parent, initialId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Route fromId to toId by inserting tombstones. */
|
||||||
|
const connectNodes = (state, fromId, toId) => {
|
||||||
|
const root = getRootNode(state, fromId);
|
||||||
|
|
||||||
|
if (root !== toId) {
|
||||||
|
return insertTombstone(state, toId, fromId);
|
||||||
|
} else {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const importBranch = (state, statuses, statusId) => {
|
||||||
return state.withMutations(state => {
|
return state.withMutations(state => {
|
||||||
statuses.forEach((status, i) => {
|
statuses.forEach((status, i) => {
|
||||||
const lastId = rootId && i === 0 ? rootId : (statuses[i - 1] || {}).id;
|
const prevId = statusId && i === 0 ? statusId : (statuses[i - 1] || {}).id;
|
||||||
|
|
||||||
if (status.in_reply_to_id) {
|
if (status.in_reply_to_id) {
|
||||||
importStatus(state, status);
|
importStatus(state, status);
|
||||||
} else if (lastId) {
|
connectNodes(state, status.id, statusId);
|
||||||
insertTombstone(state, lastId, status.id);
|
} else if (prevId) {
|
||||||
|
insertTombstone(state, prevId, status.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue