Skip to content

Commit

Permalink
fix newly created threads not loading correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Oct 17, 2022
1 parent 6b1f5e9 commit 21f777c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
public readonly room: Room;
public readonly client: MatrixClient;

public initialEventsFetched = !Thread.hasServerSideSupport;

constructor(
public readonly id: string,
public rootEvent: MatrixEvent | undefined,
Expand Down Expand Up @@ -242,6 +244,7 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {

this.client.decryptEventIfNeeded(event, {});
} else if (!toStartOfTimeline &&
this.initialEventsFetched &&
event.localTimestamp > this.lastReply()?.localTimestamp
) {
await this.fetchEditsWhereNeeded(event);
Expand Down Expand Up @@ -290,6 +293,22 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
await this.processEvent(this.lastEvent);
}

if (!this.initialEventsFetched) {
this.initialEventsFetched = true;
// fetch initial event to allow proper pagination
try {
// if the thread has regular events, this will just load the last reply.
// if the thread is newly created, this will load the root event.
await this.client.paginateEventTimeline(this.liveTimeline, { backwards: true, limit: 1 });
// just to make sure that, if we've created a timeline window for this thread before the thread itself
// existed (e.g. when creating a new thread), we'll make sure the panel is force refreshed correctly.
this.emit(RoomEvent.TimelineReset, this.room, this.timelineSet, true);
} catch (e) {
logger.error("Failed to load start of newly created thread: ", e);
this.initialEventsFetched = false;
}
}

this.emit(ThreadEvent.Update, this);
}

Expand Down

0 comments on commit 21f777c

Please sign in to comment.