Skip to content

Commit

Permalink
fix jumping to events by link
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Oct 17, 2022
1 parent a1f2469 commit b507b12
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/timeline-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class TimelineWindow {
*
* @return {Promise}
*/
public async load(initialEventId?: string, initialWindowSize = 20): Promise<void> {
public load(initialEventId?: string, initialWindowSize = 20): Promise<void> {
// given an EventTimeline, find the event we were looking for, and initialise our
// fields so that the event in question is in the middle of the window.
const initFields = (timeline: EventTimeline) => {
Expand Down Expand Up @@ -127,11 +127,16 @@ export class TimelineWindow {

// We avoid delaying the resolution of the promise by a reactor tick if we already have the data we need,
// which is important to keep room-switching feeling snappy.
const timeline = initialEventId
? await this.client.getEventTimeline(this.timelineSet, initialEventId)
: this.timelineSet.getLiveTimeline();

return initFields(timeline);
if (this.timelineSet.getTimelineForEvent(initialEventId)) {
initFields(this.timelineSet.getTimelineForEvent(initialEventId));
return Promise.resolve();
} else if (initialEventId) {
return this.client.getEventTimeline(this.timelineSet, initialEventId)
.then(initFields);
} else {
initFields(this.timelineSet.getLiveTimeline());
return Promise.resolve();
}
}

/**
Expand Down Expand Up @@ -295,8 +300,7 @@ export class TimelineWindow {
}).then((r) => {
debuglog("TimelineWindow: request completed with result " + r);
if (!r) {
// end of timeline
return false;
return this.paginate(direction, size, false, 0);
}

// recurse to advance the index into the results.
Expand Down

0 comments on commit b507b12

Please sign in to comment.