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

Commit 715b3ea

Browse files
committed
initial working poc solution
1 parent ca6f989 commit 715b3ea

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

src/components/structures/ThreadPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ const ThreadPanel: React.FC<IProps> = ({
230230

231231
useEffect(() => {
232232
if (timelineSet && !Thread.hasServerSideSupport) {
233+
timelineSet.resetLiveTimeline();
233234
timelinePanel.current.refreshTimeline();
234235
}
235236
}, [timelineSet, timelinePanel]);

src/components/structures/ThreadView.tsx

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { Room } from 'matrix-js-sdk/src/models/room';
2020
import { IEventRelation, MatrixEvent } from 'matrix-js-sdk/src/models/event';
2121
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
2222
import { Direction } from 'matrix-js-sdk/src/models/event-timeline';
23-
import { IRelationsRequestOpts } from 'matrix-js-sdk/src/@types/requests';
2423
import { logger } from 'matrix-js-sdk/src/logger';
2524
import classNames from 'classnames';
2625

@@ -195,9 +194,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
195194
thread,
196195
}, async () => {
197196
thread.emit(ThreadEvent.ViewThread);
198-
await thread.fetchInitialEvents();
199-
this.nextBatch = thread.liveTimeline.getPaginationToken(Direction.Backward);
200-
this.timelinePanel.current?.refreshTimeline();
197+
this.timelinePanel.current?.refreshTimeline(this.props.initialEvent?.getId());
201198
});
202199
}
203200
};
@@ -242,35 +239,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
242239
}
243240
};
244241

245-
private nextBatch: string;
246-
247242
private onPaginationRequest = async (
248243
timelineWindow: TimelineWindow | null,
249244
direction = Direction.Backward,
250245
limit = 20,
251246
): Promise<boolean> => {
252-
if (!Thread.hasServerSideSupport) {
253-
timelineWindow.extend(direction, limit);
254-
return true;
255-
}
256-
257-
const opts: IRelationsRequestOpts = {
258-
limit,
259-
};
260-
261-
if (this.nextBatch) {
262-
opts.from = this.nextBatch;
263-
}
264-
265-
const { nextBatch } = await this.state.thread.fetchEvents(opts);
266-
267-
this.nextBatch = nextBatch;
268-
269-
// Advances the marker on the TimelineWindow to define the correct
270-
// window of events to display on screen
271-
timelineWindow.extend(direction, limit);
272-
273-
return !!nextBatch;
247+
return timelineWindow.paginate(direction, limit);
274248
};
275249

276250
private onFileDrop = (dataTransfer: DataTransfer) => {

src/utils/EventUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ export async function fetchInitialEvent(
238238
) {
239239
const threadId = initialEvent.threadRootId;
240240
const room = client.getRoom(roomId);
241+
const mapper = client.getEventMapper();
242+
const rootEvent = room.findEventById(threadId)
243+
?? mapper(await client.fetchRoomEvent(roomId, threadId));
241244
try {
242-
room.createThread(threadId, room.findEventById(threadId), [initialEvent], true);
245+
const thread = room.createThread(threadId, rootEvent, [initialEvent], true);
246+
initialEvent.setThread(thread);
243247
} catch (e) {
244248
logger.warn("Could not find root event: " + threadId);
245249
}

0 commit comments

Comments
 (0)