Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix threads timeline message ordering (#7968)
Browse files Browse the repository at this point in the history
  • Loading branch information
Germain authored Mar 3, 2022
1 parent 75abf03 commit acd12c3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/components/structures/ThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down Expand Up @@ -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;
}

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 timelineWindow.paginate(direction, limit);
return !!nextBatch;
};

private onFileDrop = (dataTransfer: DataTransfer) => {
Expand Down
16 changes: 16 additions & 0 deletions src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { RoomMember, RoomMemberEvent } from 'matrix-js-sdk/src/models/room-membe
import { debounce } from 'lodash';
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { Thread } from 'matrix-js-sdk/src/models/thread';

import SettingsStore from "../../settings/SettingsStore";
import { Layout } from "../../settings/enums/Layout";
Expand Down Expand Up @@ -540,6 +541,21 @@ class TimelinePanel extends React.Component<IProps, IState> {
// ignore events for other timeline sets
if (data.timeline.getTimelineSet() !== this.props.timelineSet) return;

if (!Thread.hasServerSideSupport && this.context.timelineRenderingType === TimelineRenderingType.Thread) {
// const direction = toStartOfTimeline ? Direction.Backward : Direction.Forward;
// this.timelineWindow.extend(direction, 1);
if (toStartOfTimeline && !this.state.canBackPaginate) {
this.setState({
canBackPaginate: true,
});
}
if (!toStartOfTimeline && !this.state.canForwardPaginate) {
this.setState({
canForwardPaginate: true,
});
}
}

// ignore anything but real-time updates at the end of the room:
// updates from pagination will happen when the paginate completes.
if (toStartOfTimeline || !data || !data.liveEvent) return;
Expand Down
2 changes: 1 addition & 1 deletion src/stores/notifications/ThreadNotificationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ThreadNotificationState extends NotificationState implements IDestr
const isOwn = myUserId === event.getSender();
const readReceipt = this.thread.room.getReadReceiptForUserId(myUserId);

if (!isOwn && !readReceipt || event.getTs() >= readReceipt.data.ts) {
if (!isOwn && !readReceipt || (readReceipt && event.getTs() >= readReceipt.data.ts)) {
const actions = client.getPushActionsForEvent(event, true);

if (actions?.tweaks) {
Expand Down

0 comments on commit acd12c3

Please sign in to comment.