Skip to content

Commit

Permalink
Detect cycles when looking for predecessor rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
dbkr committed Jul 29, 2024
1 parent 5feab37 commit 7929989
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5401,10 +5401,15 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa

private findPredecessorRooms(room: Room, verifyLinks: boolean, msc3946ProcessDynamicPredecessor: boolean): Room[] {
const ret: Room[] = [];
const seenRoomIDs = new Set<string>([room.roomId]);

// Work backwards from newer to older rooms
let predecessorRoomId = room.findPredecessor(msc3946ProcessDynamicPredecessor)?.roomId;
while (predecessorRoomId !== null) {
if (predecessorRoomId) {
if (seenRoomIDs.has(predecessorRoomId)) return ret;
seenRoomIDs.add(predecessorRoomId);
}
const predecessorRoom = this.getRoom(predecessorRoomId);
if (predecessorRoom === null) {
break;
Expand Down

0 comments on commit 7929989

Please sign in to comment.