From 3a1321b58ed377af8d70208fba51f18ca307fe53 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 9 Dec 2021 17:59:28 +0000 Subject: [PATCH 1/2] Automatically scrollback in room when searching for MSC3089 branch event --- src/models/MSC3089Branch.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/models/MSC3089Branch.ts b/src/models/MSC3089Branch.ts index 46dd52b9a4a..9f33884939f 100644 --- a/src/models/MSC3089Branch.ts +++ b/src/models/MSC3089Branch.ts @@ -140,7 +140,14 @@ export class MSC3089Branch { const room = this.client.getRoom(this.roomId); if (!room) throw new Error("Unknown room"); - const event = room.getUnfilteredTimelineSet().findEventById(this.id); + let event: MatrixEvent | undefined = room.getUnfilteredTimelineSet().findEventById(this.id); + + // keep scrolling back if needed until we find the event or reach the start of the room: + while (!event && room.oldState.paginationToken) { + await this.client.scrollback(room, 100); + event = room.getUnfilteredTimelineSet().findEventById(this.id); + } + if (!event) throw new Error("Failed to find event"); // Sometimes the event isn't decrypted for us, so do that. We specifically set `emit: true` From 451ea8c8420a4c951f73862ec100a6ddcdb57aa2 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Tue, 14 Dec 2021 09:18:46 +0000 Subject: [PATCH 2/2] Don't use legacy room.oldState and instead explicitly use timeline --- src/models/MSC3089Branch.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/MSC3089Branch.ts b/src/models/MSC3089Branch.ts index 9f33884939f..68ca88207ec 100644 --- a/src/models/MSC3089Branch.ts +++ b/src/models/MSC3089Branch.ts @@ -18,6 +18,7 @@ import { MatrixClient } from "../client"; import { IEncryptedFile, RelationType, UNSTABLE_MSC3089_BRANCH } from "../@types/event"; import { IContent, MatrixEvent } from "./event"; import { MSC3089TreeSpace } from "./MSC3089TreeSpace"; +import { EventTimeline } from "./event-timeline"; import type { ReadStream } from "fs"; /** @@ -143,7 +144,7 @@ export class MSC3089Branch { let event: MatrixEvent | undefined = room.getUnfilteredTimelineSet().findEventById(this.id); // keep scrolling back if needed until we find the event or reach the start of the room: - while (!event && room.oldState.paginationToken) { + while (!event && room.getLiveTimeline().getState(EventTimeline.FORWARDS).paginationToken) { await this.client.scrollback(room, 100); event = room.getUnfilteredTimelineSet().findEventById(this.id); }