Fix threads timeline message ordering (#7968)

This commit is contained in:
Germain 2022-03-03 15:22:16 +00:00 committed by GitHub
parent 75abf03fed
commit acd12c38a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 12 deletions

View file

@ -186,8 +186,10 @@ export default class ThreadView extends React.Component<IProps, IState> {
}, async () => {
thread.emit(ThreadEvent.ViewThread);
if (!thread.initialEventsFetched) {
await thread.fetchInitialEvents();
const { nextBatch } = await thread.fetchInitialEvents();
this.nextBatch = nextBatch;
}
this.timelinePanel.current?.refreshTimeline();
});
}
@ -241,29 +243,35 @@ export default class ThreadView extends React.Component<IProps, IState> {
}
};
private nextBatch: string;
private onPaginationRequest = async (
timelineWindow: TimelineWindow | null,
direction = Direction.Backward,
limit = 20,
): Promise<boolean> => {
if (!Thread.hasServerSideSupport) {
return false;
timelineWindow.extend(direction, limit);
return true;
}
const timelineIndex = timelineWindow.getTimelineIndex(direction);
const paginationKey = direction === Direction.Backward ? "from" : "to";
const paginationToken = timelineIndex.timeline.getPaginationToken(direction);
const opts: IRelationsRequestOpts = {
limit,
[paginationKey]: paginationToken,
direction,
};
await this.state.thread.fetchEvents(opts);
if (this.nextBatch) {
opts.from = this.nextBatch;
}
return timelineWindow.paginate(direction, limit);
const { nextBatch } = await this.state.thread.fetchEvents(opts);
this.nextBatch = nextBatch;
// Advances the marker on the TimelineWindow to define the correct
// window of events to display on screen
timelineWindow.extend(direction, limit);
return !!nextBatch;
};
private onFileDrop = (dataTransfer: DataTransfer) => {